This is my code, I was following along the tutorial as best as I could. I Googled and it said basically you can’t have stuff in-between namespaces, but I am not doing so AFAIK.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;
namespace RPG.Control {
public class PlayerController : MonoBehaviour {
}
private void Update()
{
if (Input.GetMouseButton(0))
{
MoveToCursor();
}
}
private void MoveToCursor()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool hasHit = Physics.Raycast(ray, out hit);
if (hasHit)
{
GetComponent<Mover>().MoveTo(hit.point);
}
}
}
The closing bracket underneath this statement is saying that this is the sum and total of the class.
You’ll need to remove that bracket and put another bracket before the last bracket in the script to put the methods and fields in the PlayerController class and close it out.
I know the problem is below but I can’t figure out how to solve it. I’ve done it before.
This is the new error.
Assets\Scripts\PlayerController.cs(27,30): error CS0246: The type or namespace name ‘Fighter’ could not be found (are you missing a using directive or an assembly reference?)
namespace RPG.Control {
public class PlayerController : MonoBehaviour {
private void Update()
{
InteractWithCombat();
InteractWithMovement();
}
private void InteractWithCombat()
{
RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
foreach (RaycastHit hit in hits)
{
CombatTarget target = hit.transform.GetComponent<CombatTarget>();
if (target == null) continue;
if (Input.GetMouseButtonDown(0))
{
GetComponent<Fighter>().Attack(target);
}
}
}
private void InteractWithMovement()
{
if (Input.GetMouseButton(0))
{
MoveToCursor();
}
}
private void MoveToCursor()
{
RaycastHit hit;
bool hasHit = Physics.Raycast(GetMouseRay(), out hit);
if (hasHit)
{
GetComponent<Mover>().MoveTo(hit.point);
}
}
private static Ray GetMouseRay()
{
return Camera.main.ScreenPointToRay(Input.mousePosition);
}
}
}
Paste your current script (the whole script) in again (as line 14 won’t be the same anymore).
Before pasting in the script, type three backwards apostrophes on a new line, then on the next line press paste.
example:
```
Some Code
```
becomes
It looks like you copied from the Diff (which is what we see when we go to the commit)… You’ll notice it has a lot of + and - on the left hand side which aren’t copied. There were many areas that were removed (the - sign next to the line) and sections that were added (the + sign next to the line).
Here’s the corrected script:
using System;
using RPG.Combat;
using RPG.Movement;
using UnityEngine;
namespace RPG.Control
{
public class PlayerController : MonoBehaviour
{
private void Update()
{
if (InteractWithCombat()) return;
if (InteractWithMovement()) return;
}
private bool InteractWithCombat()
{
RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
foreach (RaycastHit hit in hits)
{
CombatTarget target = hit.transform.GetComponent<CombatTarget>();
if (target == null) continue;
if (Input.GetMouseButtonDown(0))
{
GetComponent<Fighter>().Attack(target);
}
return true;
}
return false;
}
private bool InteractWithMovement()
{
RaycastHit hit;
bool hasHit = Physics.Raycast(GetMouseRay(), out hit);
if (hasHit)
{
GetComponent<Mover>().MoveTo(hit.point);
if (Input.GetMouseButton(0))
{
GetComponent<Mover>().MoveTo(hit.point);
}
return true;
}
return false;
}
private static Ray GetMouseRay()
{
return Camera.main.ScreenPointToRay(Input.mousePosition);
}
}
}