using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
bool joueurVu = false;
public GameObject joueur;
void Start () {
joueur = gameObject.Find ("First Person Controller");
}
// Update is called once per frame
void Update () {
if (getDistance() < 5)
{
joueurVu = true;
print ("joueur vu !");
}
}
}
return Vector3.Distance(joueur.Transform.position, Transform.position);
float getDistance(){
}
This is my code its says that at line 23 the error is and i dont know how to fix it
So can you tell me what i have to write ? im starting in C# and unity 3d coding and i create this script for a pnj character who follow my hero when he gets close to him,
using UnityEngine;
using System.Collections;
public class IA : MonoBehaviour {
bool joueurVu = false;
public GameObject joueur;
void Start () {
joueur = gameObject.Find ("First Person Controller");
}
// Update is called once per frame
void Update () {
if (getDistance() < 5)
{
joueurVu = true;
print ("joueur vu !");
}
}
float getDistance(){
return Vector3.Distance(joueur.Transform.position, Transform.position);
}
}
this is the new code now i have 3 errors
line 12 error cs0176
The member ‘UnityEngine.GameObject.Find (string)’ is inaccessible with an instance reference; Qualify it with a type name (CS0176) (Assembly-CSharp)
line 24 error cs1061
‘UnityEngine.GameObject’ does not contain a definition for ‘Transform’ and no ‘Transform’ extension method accepting A first argument of type ‘UnityEngine.GameObject’ was found (a using directive or an assembly reference is missing?) (CS1061) (Assembly-CSharp)
line 24 error cs0120
An object reference is required for the property, method, or non-static field 'UnityEngine.Transform.position .get '(CS0120) (Assembly-CSharp)
Seems like you’re starting with programming period. What I would do is follow some basic programming tutorials (check my sig) and learn those basics first. After that you should be able to figure these errors out yourself. Also next time please post the entire error and not just the code, it’s not like we all know the entire error code list from the top of our heads
I still cant fix it .I had over 141 complier errors and deleted my code only leaving a lowercase U not knowing what to do .I now have 2 complier errors one of them being cs0116 and the other
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Scripting.ScriptCompilation.CSharpNamespaceParser.CollectNamespace (UnityEditor.Scripting.ScriptCompilation.CSharpNamespaceParser+Node parent) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEditor.Scripting.ScriptCompilation.CSharpNamespaceParser.FindClassAndNamespace (System.String className, System.String source, System.Boolean acceptStruct) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEditor.Scripting.ScriptCompilation.CSharpNamespaceParser.FindNamespace (System.String sourceCode, System.String className, System.Boolean acceptStruct, System.String[ ] defines) (at <2f1c602eae0d45c293fff3e3aef75
9fa>:0)
UnityEditor.Scripting.Compilers.CSharpLanguage.GetClassAndNamespace (System.String filePath, System.String definedSymbols, System.String& outClassName, System.String& outNamespace) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEditor.Scripting.ScriptCompilers.GetClassAndNamespace (System.String file, System.String definedSymbols,
please help
The answer is always the same… ALWAYS. It is the single most common error ever. Don’t waste your life on this problem. Instead, learn how to fix it fast… it’s EASY!!
Some notes on how to fix a NullReferenceException error in Unity3D
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
This is the kind of mindset and thinking process you need to bring to this problem: