TargetMark.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TargetMark : MonoBehaviour {
  4. private BattleController battleController;
  5. // Use this for initialization
  6. public void init(BattleController battleController)
  7. {
  8. this.battleController = battleController;
  9. }
  10. // Update is called once per frame
  11. void Update ()
  12. {
  13. if(battleController == null) return;
  14. if(battleController.GetCtrlCraft() == null)
  15. {
  16. if(GetComponent<Renderer>().enabled)
  17. GetComponent<Renderer>().enabled = false;
  18. }
  19. else if(battleController.GetCtrlCraft().target != null && battleController.GetCtrlCraft().target.CanShoot())
  20. {
  21. if(!GetComponent<Renderer>().enabled)
  22. GetComponent<Renderer>().enabled = true;
  23. Vector3 position = battleController.GetCtrlCraft().target.position;
  24. position.y = 0.01f;
  25. this.transform.position = position;
  26. this.transform.localRotation = Quaternion.Euler(270, GameTime.time*180f, 0);
  27. float scale = 1.8f+0.2f*Mathf.Sin(GameTime.time*5f);
  28. this.transform.localScale = new Vector3(scale, scale, scale);
  29. }
  30. else if(battleController.GetCtrlCraft().target != null && battleController.GetCtrlCraft().target.CanShoot())
  31. {
  32. if(!GetComponent<Renderer>().enabled)
  33. GetComponent<Renderer>().enabled = true;
  34. Vector3 position = battleController.GetCtrlCraft().target.position;
  35. position.y = 0.01f;
  36. this.transform.position = position;
  37. this.transform.localRotation = Quaternion.Euler(270, GameTime.time*180f, 0);
  38. float scale = 1.8f+0.2f*Mathf.Sin(GameTime.time*5f);
  39. this.transform.localScale = new Vector3(scale, scale, scale);
  40. }
  41. else
  42. {
  43. if(GetComponent<Renderer>().enabled)
  44. GetComponent<Renderer>().enabled = false;
  45. }
  46. }
  47. }