void Awake() { instance = this; MaxLength = MaxFishCount * FishGap; Trail = new List <Vector3>(); FishList = new List <GameObject>(); for (int i = 0; i < MaxLength; i++) { Trail.Add(transform.position); } }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Fish")) { GameObject.FindGameObjectWithTag("UniqueSoundObject").GetComponent <AudioSource>().PlayOneShot(other.GetComponent <FishSounds>().FishDeathSound); BuildFishTrail.RemoveFish(other.gameObject); } if (other.CompareTag("Ocean") && LifeTime > 0.5f) { InWater = true; } }
void OnTriggerEnter(Collider other) { Debug.Log(other.tag + " Collided"); if (other.CompareTag("Fish")) { if (other.GetComponent <FishType>().myType == myType) { Source.PlayOneShot(other.GetComponent <FishSounds>().FishGetsHomeSound); Debug.Log("Same type"); BuildFishTrail.RemoveFish(other.gameObject); GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>().Score++; Destroy(this.gameObject, 3f); } } }
void OnTriggerEnter(Collider col) { if (col.CompareTag("Fish")) { if (BuildFishTrail.FishList.IndexOf(col.gameObject) == -1 && BuildFishTrail.FishList.Count < BuildFishTrail.MaxFishCount) { BuildFishTrail.AddFish(col.gameObject); foreach (Transform t in col.transform) { if (t.gameObject.name.Equals("FishCollectIndicator")) { Destroy(t.gameObject); } } } } }
private void SpawnFish() { int length = BuildFishTrail.FishList.Count; for (int i = 0; i < length; i++) { BuildFishTrail.RemoveFish(0); } for (int i = 0; i < BuildFishTrail.Trail.Count; i++) { BuildFishTrail.Trail[i] = transform.position; } for (int i = 0; i < 3; i++) { Transform g = Instantiate(FishType[i], transform.position, Quaternion.identity); } }
/* * public void AddFish() * { * int index = FishGap+InitialGap; * if(FishList.Count > 0) * index = FishList[FishList.Count-1].GetComponent<FollowTrail>().desiredIndex+FishGap; * if(index >= MaxLength){ * //currently, do not make fish if they go beyond the maximum trail length * return; * } * Transform fish = Instantiate(FishPrefab,Trail[index],Quaternion.identity); * fish.GetComponent<FollowTrail>().currentIndex = Mathf.Min(MaxLength,index); * fish.GetComponent<FollowTrail>().desiredIndex = index; * FishList.Add(fish.gameObject); * } */ public static void AddFish(GameObject g) { BuildFishTrail instance = BuildFishTrail.instance; int index = instance.InitialGap + instance.FishGap; g.GetComponent <FollowTrail>().enabled = true; if (FishList.Count > 0) { index = FishList[FishList.Count - 1].GetComponent <FollowTrail>().desiredIndex + instance.FishGap; } if (index >= instance.MaxLength) { //currently, do not make fish if they go beyond the maximum trail length return; } g.GetComponent <FollowTrail>().currentIndex = Mathf.Min(instance.MaxLength, index); g.GetComponent <FollowTrail>().desiredIndex = index; FishList.Add(g); Debug.Log("Added: " + FishList.IndexOf(g)); }