Question by
emir3100 · Mar 29, 2016 at 11:57 AM ·
transformnavmeshagentboolswitch characters
What am i doing wrong (AI hiding system)
I'm doing an AI hiding system, I got no errors. I'm trying to switch the target to waypointer. When I switch the bool to false or true it won't work. am I doing it wrong or is there a other way to do it?
NavMeshAgent agent;
public Transform target;
public Transform waypointer;
public bool hiding = true;
void Start ()
{
agent = GetComponent<NavMeshAgent> ();
}
void Update () {
agent.SetDestination(target.position);
if(hiding = false)
waypointer = target;
{
if(hiding = true)
target = waypointer;
}
}
}
Comment
Best Answer
Answer by gjf · Mar 28, 2016 at 11:01 PM
if(hiding = false)
is an assignment not a comparison. it should be
if(hiding == false)
or use the shorthand:
if(!hiding)
the code following that should probably be:
else
{
target = waypointer;
}
but since it's not entirely clear whether you always want to set it the other way round, that might not be the case ;)
Thanks for helping me. And everything works. The only problem is that it doesn't work in game. When I switch the bool off/on it won't work. Only works when the game is not playing. Is there a solution for this? Thanks again for help.