Dj6974
New member
- Joined
- Aug 28, 2022
- Messages
- 3
- Programming Experience
- Beginner
I'm making a 3D game in Unity and I'm using the NavMesh to move the main character around the game. The code to move the player works fine unless I try to add a boolean to the mix. I want to make it so the player only moves when a certain bool is true. But when I do this, the player doesn't move at all whether the bool is true or not.
Works fine.
Doesn't work at all.
C#:
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100))
{
agent.SetDestination(hit.point);
}
}
}
C#:
void Update()
{
if (Input.GetMouseButtonDown(0) && somebool == true)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100))
{
agent.SetDestination(hit.point);
}
}
}
Last edited: