private void Start() { em = GameObject.Find("MenuHandler").GetComponent <EscapeMenu>(); anim = this.GetComponent <Animator>(); rb = this.GetComponent <Rigidbody2D>(); itemDisplay = this.transform.GetChild(0).gameObject.GetComponent <ItemDisplay>(); if (anim == null) { Debug.LogError("Couldn't find the animator on gameobject: " + this.gameObject.name); } if (rb == null) { Debug.LogError("Couldn't find the rigidbody2D on gameobject: " + this.gameObject.name); } if (itemDisplay == null) { Debug.LogError("Couldn't find the itemdisplay on gameobject: " + this.gameObject.name); } itemDisplay.StartCoroutine("UpdateItem"); }
private void Update() { if (fp.fireHP <= 0 || em.paused == true) { return; } if (Input.GetKeyDown(KeyCode.Space)) { DropItem(); } if (Input.GetButtonDown("Fire1") && currentItem != null && currentItem.type == Item.ItemType.LOG) { Vector3 fireAt = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -0.01f)); GameObject newProj = Instantiate(projectile); newProj.transform.position = this.transform.position; newProj.GetComponent <ProjectileController>().setDestination(fireAt); newProj.GetComponent <ProjectileController>().addPierce(pierceBonus); currentItem = null; itemDisplay.StartCoroutine("UpdateItem"); } movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical"); if (movement.y > 0) { dir = currentDir.UP; } else if (movement.y < 0) { dir = currentDir.DOWN; } else if (movement.x > 0) { dir = currentDir.RIGHT; } else if (movement.x < 0) { dir = currentDir.LEFT; } anim.SetFloat("Horizontal", movement.x); anim.SetFloat("Vertical", movement.y); anim.SetFloat("Speed", movement.magnitude); if (movement.magnitude > 0.01 || movement.magnitude < -0.01) { audio1.UnPause(); } else { audio1.Pause(); } switch (dir) { case currentDir.DOWN: anim.SetInteger("DIR", 2); break; case currentDir.UP: anim.SetInteger("DIR", 0); break; case currentDir.RIGHT: anim.SetInteger("DIR", 1); break; case currentDir.LEFT: anim.SetInteger("DIR", 3); break; } }