- Home /
Question by
ninjixfatality · Mar 15, 2018 at 03:54 AM ·
rigidbodyraycastprefabwaypoints
How to stop waypoints script in another script?
I'm making an aquatic experience game. I want the fish to stop as soon as Raycast hits the collider of the prefab but im unsure how to write an if statement in order to start and stop the prefab from moving.
public class Waypoints : MonoBehaviour {
public float time_min = 1.0f;
public float time_max = 3.0f;
public float speed = 3.0f;
//public int[] animVal = { 0, 1, 2 };
public GameObject[] waypoints;
public int num = 0;
public float minDist = 1.0f;
public bool rand = false;
public bool go = true;
//private Animator anim;
private Rigidbody rb;
void Start () {
//anim = GetComponentInChildren<Animator>();
rb = GetComponent<Rigidbody> ();
//StartCoroutine(ChangeAnimation());
}
void Update () {
float dist = Vector3.Distance
(gameObject.transform.position, waypoints[num].transform.position);
//if (anim.GetInteger ("pickAnim") == 1) {
if (go) {
if (dist > minDist) {
Move ();
} else {
if (!rand) {
if (num + 1 == waypoints.Length) {
num = 0;
} else {
num++;
}
} else {
num = Random.Range (0, waypoints.Length);
}
}
}
}
//}
public void Move (){
gameObject.transform.LookAt (waypoints[num].transform.position);
gameObject.transform.position += gameObject.transform.forward * speed * Time.deltaTime;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154629im_/https://answers.unity.com/themes/thub/images/avi.jpg)