I have the following scenario:
a sphere is moving towards an object it can see (a cube). The cube is moving randomly through the landscape. The sphere will keep following it. I have a script that will check IF the cube is Within Sight. If it is, it will move towards it and it will keep following it.
What I want
I want a Debug.Log message to show when:
- When the sphere is moving towards a (new) target. it must say: "Searching..."
- When the sphere has found the cube, I want it to say: "Found the cube."
- When the cube is found, I want it to continue searching for new cubes. So it must say once more: "Searching..."
Problem:
It keeps showing these messages nonstop. I found a solution with a false bool in an IF statement. But, I don't know how to combine 2 messages.
Code:
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
public class MoveTowards : Action {
public float speed = 0;
public SharedTransform target;
private bool pietje;
private bool jaap;
void PrintMessage (string message) {
Debug.Log(message);
}
void Start() {
pietje = false;
}
public override TaskStatus OnUpdate() {
if (Vector3.SqrMagnitude (transform.position - target.Value.position) < 0.1f && !pietje) {
PrintMessage ("Found the cube.");
pietje = true;
return TaskStatus.Success;
}
transform.position = Vector3.MoveTowards (transform.position, target.Value.position, speed * Time.deltaTime);
transform.LookAt (target.Value.position);
return TaskStatus.Running;
}
}
I just don't know how to fix the last part where it says: "Searching..." I don't know how to implement it with an IF statement (doesn't work somehow) or how to create the IF statement (when I use this, it doesn't work:
if (TaskStatus.Running == 1 && !pietje)
Anyone that can help me? That would be awesome! Have been trying to fix this for some hours now....