// Update is called once per frame void Update() { if (active) { KeyBoardHelperScript kbh = GameObject.Find("KeyBoardHelper").GetComponent <KeyBoardHelperScript>(); if (cooldown == shotInterval && kbh.spaceKeyHeld) { Fire(); GameObject.Find("SoundFX").GetComponent <SoundFXHelperScript>().PlayerShotSound(); cooldown = 0.0f; } else { if (cooldown >= shotInterval) { cooldown = shotInterval; } else { cooldown = cooldown + Time.deltaTime; } } } }
void Update() { KeyBoardHelperScript kbh = GameObject.Find("KeyBoardHelper").GetComponent <KeyBoardHelperScript>(); EnemyMoveScript2 parent = gameObject.GetComponent <EnemyMoveScript2>(); if (cooldown == shotInterval && parent.inPlace) { Fire(); GameObject.Find("SoundFX").GetComponent <SoundFXHelperScript>().EnemyShotSound(); cooldown = 0.0f; } else { if (cooldown >= shotInterval) { cooldown = shotInterval; } else { cooldown = cooldown + Time.deltaTime; } } }
// Update is called once per frame void Update() { destination = GameObject.Find("MouseHelper").GetComponent <MouseHelperScript>().mousePos2D; KeyBoardHelperScript kbh = GameObject.Find("KeyBoardHelper").GetComponent <KeyBoardHelperScript>(); currentPos = new Vector2(transform.position.x, transform.position.y); distanceX = destination.x - currentPos.x; distanceY = destination.y - currentPos.y; angle = Mathf.Atan2(distanceY, distanceX); angle = angle * (180.0f / Mathf.PI); ratio.x = Mathf.Cos(angle * (Mathf.PI / 180.0f)); ratio.y = Mathf.Sin(angle * (Mathf.PI / 180.0f)); transform.eulerAngles = new Vector3(0.0f, 0.0f, angle); //Right Movement if (kbh.rightKeyHeld) { if (momentumX < accelCap) { momentumX = momentumX + acceleration * Time.deltaTime; } } else if (momentumX > 0.0f) { momentumX = momentumX - acceleration * Time.deltaTime; if (momentumX < 0) { momentumX = 0; } } //Left Movement if (kbh.leftKeyHeld) { if (-momentumX < accelCap) { momentumX = momentumX - acceleration * Time.deltaTime; } } else if (-momentumX > 0.0f) { momentumX = momentumX + acceleration * Time.deltaTime; if (momentumX > 0) { momentumX = 0; } } if (kbh.upKeyHeld) { if (momentumY < accelCap) { momentumY = momentumY + acceleration * Time.deltaTime; } } else if (momentumY > 0.0f) { momentumY = momentumY - acceleration * Time.deltaTime; if (momentumY < 0) { momentumY = 0; } } if (kbh.downKeyHeld) { if (-momentumY < accelCap) { momentumY = momentumY - acceleration * Time.deltaTime; } } else if (-momentumY > 0.0f) { momentumY = momentumY + acceleration * Time.deltaTime; if (momentumY > 0) { momentumY = 0; } } transform.Translate(new Vector3(1.0f, 0.0f, 0.0f) * momentumX * Time.deltaTime, Space.World); transform.Translate(new Vector3(0.0f, 1.0f, 0.0f) * momentumY * Time.deltaTime, Space.World); }