void Start() { gameObject = GameObject.Find("shooting"); shootingArrow = gameObject.GetComponent <ShootingArrow>(); Shot = true; Anime = GetComponent <Animation>(); animator = this.GetComponent <Animator>(); this.LimitTime = GameObject.Find("LimitTime"); this.showgameover = GameObject.Find("RedGameover"); this.restartimage = GameObject.Find("Restart"); this.restartbutton = GameObject.Find("RestartText"); this.textgameover = GameObject.Find("GameOverText"); this.killscore = GameObject.Find("KillScore"); showgameover.GetComponent <Image>().enabled = false; textgameover.GetComponent <Text>().enabled = false; //killscore.GetComponent<Text>().enabled = false; audioSource = GetComponent <AudioSource>(); soundcheck = false; deathcheckcount = false; }
// Update is called once per frame void Update() { if (attacking) { if (attackTimeCounter > 0) { mybody.velocity = Vector2.zero; attackTimeCounter -= Time.deltaTime; } if (attackTimeCounter <= 0) { attacking = false; anim.SetBool("Attacking", false); } } else { if (moving) { switch (whomToAttack) { case 0: moveDirection = new Vector3((thePlayer1.transform.position.x - mybody.transform.position.x) / Mathf.Sqrt((thePlayer1.transform.position.x - mybody.transform.position.x) * (thePlayer1.transform.position.x - mybody.transform.position.x) + (thePlayer1.transform.position.y - mybody.transform.position.y) * (thePlayer1.transform.position.y - mybody.transform.position.y)) * moveSpeed, (thePlayer1.transform.position.y - mybody.transform.position.y) / Mathf.Sqrt((thePlayer1.transform.position.x - mybody.transform.position.x) * (thePlayer1.transform.position.x - mybody.transform.position.x) + (thePlayer1.transform.position.y - mybody.transform.position.y) * (thePlayer1.transform.position.y - mybody.transform.position.y)) * moveSpeed, 0); mybody.velocity = moveDirection; lastmove = moveDirection; if (Vector2.Distance(thePlayer1.transform.position, mybody.transform.position) < attackRange) { attackTimeCounter = attackTime; attacking = true; mybody.velocity = Vector2.zero; anim.SetBool("Attacking", true); GameObject arrowClone = (GameObject)Instantiate(theArrow, shootPoint.position, shootPoint.rotation); arrowClone.transform.localScale = transform.localScale; shootArrow = FindObjectOfType <ShootingArrow>(); shootArrow.direction = lastmove; } break; case 1: moveDirection = new Vector3((thePlayer2.transform.position.x - mybody.transform.position.x) / Mathf.Sqrt((thePlayer2.transform.position.x - mybody.transform.position.x) * (thePlayer2.transform.position.x - mybody.transform.position.x) + (thePlayer2.transform.position.y - mybody.transform.position.y) * (thePlayer2.transform.position.y - mybody.transform.position.y)) * moveSpeed, (thePlayer2.transform.position.y - mybody.transform.position.y) / Mathf.Sqrt((thePlayer2.transform.position.x - mybody.transform.position.x) * (thePlayer2.transform.position.x - mybody.transform.position.x) + (thePlayer2.transform.position.y - mybody.transform.position.y) * (thePlayer2.transform.position.y - mybody.transform.position.y)) * moveSpeed, 0); mybody.velocity = moveDirection; lastmove = moveDirection; if (Vector2.Distance(thePlayer2.transform.position, mybody.transform.position) < attackRange) { attackTimeCounter = attackTime; attacking = true; mybody.velocity = Vector2.zero; anim.SetBool("Attacking", true); GameObject arrowClone = (GameObject)Instantiate(theArrow, shootPoint.position, shootPoint.rotation); arrowClone.transform.localScale = transform.localScale; shootArrow = FindObjectOfType <ShootingArrow>(); shootArrow.direction = lastmove; } break; } if (Mathf.Abs(mybody.velocity.x) > 0.5f && Mathf.Abs(mybody.velocity.y) > 0.5f) { mybody.velocity = new Vector2(mybody.velocity.x * 0.7f, mybody.velocity.y * 0.7f); } } else { if (Vector2.Distance(thePlayer1.transform.position, mybody.transform.position) < range) { moving = true; whomToAttack = Random.Range(0, 2); } if (Vector2.Distance(thePlayer2.transform.position, mybody.transform.position) < range) { whomToAttack = Random.Range(0, 2); moving = true; } } } anim.SetFloat("MoveX", moveDirection.x); anim.SetFloat("MoveY", moveDirection.y); anim.SetBool("Moving", moving); anim.SetFloat("LastMoveX", lastmove.x); anim.SetFloat("LastMoveY", lastmove.y); }