void DecreasePopulation(int NewPopulation) { while (SharkPopulation.Count != NewPopulation) { SharkMovement Shark = SharkPopulation[0]; SharkPopulation.RemoveAt(0); Destroy(Shark.gameObject); } }
void IncreasePopulation(int NewPopulation) { while (SharkPopulation.Count != NewPopulation) { GameObject NewShark = Instantiate(SharkPrefab, GetRandomLocation(), Quaternion.identity) as GameObject; NewShark.transform.parent = transform; SharkMovement Shark = NewShark.GetComponent <SharkMovement>(); Shark.SharkController = this; SharkPopulation.Add(Shark); } }
public void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Shark") { PhotonView sharkView = other.gameObject.GetComponent <PhotonView>(); if (!isBit) { isBit = true; randomSound.clip = audioSources[UnityEngine.Random.Range(0, audioSources.Length)]; randomSound.Play(); em.enabled = true; blood.Play(); rBody.isKinematic = true; SharkMovement shark = other.gameObject.GetComponent <SharkMovement>(); if (sharkView.IsMine) { shark.Owner.AddScore(1); } //if there is a swimmer as a child of the ball m_Animator.SetBool("BittenAndDying", true); } } if (other.gameObject.tag == "Shore") { if (!onShore) { Vector3 newPosition = new Vector3(this.transform.position.x - 2, this.transform.position.y + 4, this.transform.position.z); this.transform.position = newPosition; swimming = false; onShore = true; m_Animator.SetBool("Swimming", false); m_Animator.SetBool("OnShore", true); } } if (other.gameObject.tag == "vanish") { PhotonView newView = other.gameObject.GetComponent <PhotonView>(); SharkMovement sharkScript = shark1.GetComponent <SharkMovement>(); foreach (Player player in PhotonNetwork.PlayerList) { player.AddScore(-1); } photonView = PhotonView.Get(this); photonView.RPC("GoodSwimmer", RpcTarget.All); } }
public override void AgentAction(float[] vectorAction, string textAction) { //Actions, size = 2 Vector3 controlSignal = Vector3.zero; controlSignal.x = vectorAction[0]; controlSignal.z = vectorAction[1]; rBody.AddForce(controlSignal * speed); float distanceToWater = Vector3.Distance(this.transform.position, target.position); float distanceToHalfEast = Vector3.Distance(this.transform.position, target2.position); float distanceToEast = Vector3.Distance(this.transform.position, target2.position); float distanceToWest = Vector3.Distance(this.transform.position, target3.position); float distanceToHalfWest = Vector3.Distance(this.transform.position, target3.position); float distancetoAvoid = Vector3.Distance(this.transform.position, Avoid.position); SharkMovement sharkScript = shark1.GetComponent <SharkMovement>(); //Reached target { //if (distanceToWater < 20.00f) //{ // SetReward(.05f); // //Done(); //} if (distancetoAvoid < 5.0f) { SetReward(-1f); } //if (distanceToHalfEast < 25.0f) //{ // SetReward(0.1f); //} //if (distanceToEast < 15.0f) //{ // if (isEast == false) // { // //sharkScript.Owner.AddScore(-1); // isEast = true; // } // SetReward(0.5f); //} //if (distanceToHalfWest < 25.0f) //{ // SetReward(0.1f); //} if (distanceToWest < 15.0f) { if (isEast == true) { sharkScript.Owner.AddScore(-1); isEast = false; } SetReward(0.5f); } if (this.transform.position.y < 0) { isReward = true; Done(); } } }