Hey I Have a Rpg game and i need help with this script
It’s supposed to Make it so when the main character goes into a trigger the bad guy moves towards it
the moving works but the trigger part errors when i enter play mode
public class LookMove : MonoBehaviour
{
Triggered trig;
public GameObject Trig;
public int Hello = 0;
public Transform target2;
public Transform target;
NavMeshAgent agent;
void Start ()
{
trig = Trig.GetComponent<Triggered>();
agent = GetComponent<NavMeshAgent>();
}
void Update ()
{
trig.Cool = Hello;
if(Hello == 1)
{
agent.SetDestination(target.position);
}
}
}
It has an error message that says something in line 16 doesn’t exist
public class Triggered : MonoBehaviour
{
public int Cool = 0;
public GameObject Trig;
void OnTriggerEnter (Collider other)
{
if(gameObject.name == "OrcTrigger")
{
Cool = 1;
}
}
}
public class LookMove : MonoBehaviour
trig.Cool = Hello;
if(Hello == 1)
[/QUOTE]
So you are setting your Cool variable inside your Triggered class to Hello(which will always be 0), then check to see if Hello is equal to 1? That code will never run since you never change the value of hello.
About your error messgae did you set your traget variable to something?
I have checked line 19, so there is either an issue with agent, which doesn’t seem to be the case, or there may be an issue with target. Did you check that target is not null?