If you have questions or comments about this lecture, here is the place for them.
Just a heads up:
C#7 introduced new output parmeters features, making it so you can declare the variable inside the parameter. So you can writte it like this:
bool hashit = Physics.Raycast(lastRay, out RaycastHit hit);
Switched target to a gem from the free gem shader pack, and added a line of code:
target.position = GetComponent<NavMeshAgent>().destination;
Dear Rick and other students
I am working on the course but the console is saying
“Assets\Scripts\Mover.cs(6,14): error CS0101: The namespace ‘’ already contains a definition for ‘Mover’”
and
“Assets\Scripts\Mover.cs(13,10): error CS0111: Type ‘Mover’ already defines a member called ‘Update’ with the same parameter types”
I have linked my code below
please can someone explain what I have done wrong and how I can fix it. I do not fully understand yet because it seems to be a problem with update and mover the name.
It was drawing a ray before and I could fire a ray and the capsule would go towards the target (not the ray)
Thank you in advance
I find I have that issue if I’ve created 2 scripts of the same name or did some sort of change to the name of class. Perhaps try copying your code into a separate doc, delete your Mover.cs and any references to it and then create a new Mover.cs with your code in it.
So, I’m using the demo scene in the Synty Studios Polygon City Pack for this, and clicking only works on the target object. My capsule player prefab does not walk to any other part of the city streets, despite these streets having a very clear and visible nav mesh on them. What could it be that I am doing wrong?
I solved it. The streets etc needed colliders for the nav mesh raycast to work!
Hi all, I have one problem with my Visual Studio Code. When I press Ctrl + Shift + Space I don’t see any hints about method parameters. Do you know why?
Hi It is possible that it explains how to solve the error since I have the same problem
Hola hermano el problema esta que creaste 2 script debes de eliminarlo no tan solo en la carpeta también debes de eliminarlo en la carpeta del proyecto.
Hi Rick! I have followed along very carefully with this lesson however my if command isn’t working and I am unsure on how to fix it. Here is my code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Mover : MonoBehaviour
{
[SerializeField] Transform target;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
MoveToCursor();
}
}
private void MoveToCursor()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool hasHit = Physics.Raycast(ray, out hit)
if (hasHit)
{
GetComponent<NavMeshAgent>().destination = hit.point;
}
}
}
I got click to move to work without too much issue, but I was wondering if it was possible to implement a WASD control scheme (and autorun) type movement as well, and how that would be achieved. I messed around with the standard assets to get it working, but I couldn’t get the two systems to play nicely with each other. I’ve only really messed around with 2d before this course, so it’s kind of new to me.
Line 19 in your code is where the problem is. you are also missing a local variable in the MoveToCursor method.
I did the same thing that was shown in the lecture, but I’m still facing the problem. Could you help me with what exactly I have to do?.
Sir i am having an error ‘‘NullReferenceException: Object reference not set to an instance of an object
mover.Update () (at Assets/Scripts/mover.cs:17)’’
i am getting this error = '‘NullReferenceException: Object reference not set to an instance of an object
mover.MoveToCursor () (at Assets/Scripts/mover.cs:23)
mover.Update () (at Assets/Scripts/mover.cs:17)’
why dont you help me
You deleted your main camera when you created your scripted camera, so when it is referencing Camera.main in line 23 it is calling an object that no longer exists. Clicking on your FollowCamera and changing the tag to MainCamera should fix it.
The Debug log makes it pretty easy to narrow down most issues too, it mentions line 23 (when it says cs: 23… it mentions line 17 as well but thats because its calling the method that has the problem), so straight away you know to go have a look there. The Camera is the only object referenced on that line, so straight away you can deduce that something is wrong there. Will help a lot in the future if you can effectively understand what the debugger is telling you.
Best of luck.
You deleted your main camera when you created your scripted camera, so when it is referencing Camera.main in line 18 it is calling an object that no longer exists. Clicking on your FollowCamera and changing the tag to MainCamera should fix it.
The Debug log makes it pretty easy to narrow down most issues too, it mentions line 23 (when it says cs: 18), so straight away you know to go have a look there. The Camera is the only object referenced on that line, so straight away you can deduce that something is wrong there. Will help a lot in the future if you can effectively understand what the debugger is telling you.
Best of luck.