Question by
Ninjix3 · Mar 21, 2018 at 06:07 AM ·
gameobjectscripting beginnerpausedisable
Freezing Prefab or deactivating its script in another?
Okay so I have this fish prefab with a waypoints movement script attached to it. I tried everything from simple fishdist = 0; to disableFish.SetActive(false); I have no other clue left on how to freeze the prefab in place. When I use any of these it continues to move. Am I doing something wrong or iterating it incorrectly?
void Update ()
{
if (Physics.Raycast (ray, out hit, maxCastDist, waterMask))
if (hit.collider != null) {
float dist = Vector3.Distance (hit.point, target.position);
Debug.Log (dist);
Instantiate (Float, hit.point, Quaternion.identity);
if (dist < fishDist) {
// stop fish in place
//fishdist = 0;
disableFish.SetActive(false);
StartCoroutine (fishWaiter ()); // delay random when fish will be "retrieved"
}
}
}
}
}
IEnumerator fishWaiter ()
{
FishLoader.SetActive (true);
//disableFish.GetComponent<Waypoints> ().enabled = false;
float waitFishtime = Mathf.Clamp01 (5f);
FishSlider.value = waitFishtime;
Debug.Log ("Timer Started");
yield return new WaitForSeconds (waitFishtime);
print ("I waited" + waitFishtime + "Sec");
Destroy (GameObject.FindWithTag ("Fish"));
FishSlider.value = 0f;
print ("You Caught The Fish!");
ScoreManager.score += scoreValue;
AchievementManager.Instance.EarnAchievment (achievmentName);
}
}
Comment
Your answer
Follow this Question
Related Questions
Closing last used window (gameobject) by esc 1 Answer
deactivate a object through c# 2 Answers
How to set gameobject dynamically in script? 0 Answers
How to check if tag collides with identical tag 1 Answer
Disable script after time 1 Answer