CannonBehavior.cs 880 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using System.Collections;
  3. public class CannonBehavior : MonoBehaviour {
  4. public Transform m_cannonRot;
  5. public Transform m_muzzle;
  6. public GameObject m_shotPrefab;
  7. public Texture2D m_guiTexture;
  8. // Use this for initialization
  9. void Start ()
  10. {
  11. }
  12. // Update is called once per frame
  13. void Update ()
  14. {
  15. if (Input.GetKey(KeyCode.LeftArrow))
  16. {
  17. m_cannonRot.transform.Rotate(Vector3.up, -Time.deltaTime * 100f);
  18. }
  19. if (Input.GetKey(KeyCode.RightArrow))
  20. {
  21. m_cannonRot.transform.Rotate(Vector3.up, Time.deltaTime * 100f);
  22. }
  23. if (Input.GetKeyDown(KeyCode.Space))
  24. {
  25. GameObject go = GameObject.Instantiate(m_shotPrefab, m_muzzle.position, m_muzzle.rotation) as GameObject;
  26. GameObject.Destroy(go, 3f);
  27. }
  28. }
  29. void OnGUI()
  30. {
  31. GUI.DrawTexture(new Rect(0f, 0f, m_guiTexture.width / 2, m_guiTexture.height / 2), m_guiTexture);
  32. }
  33. }