son_Bult_Motion.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class son_Bult_Motion : MonoBehaviour
  5. {
  6. // public Transform mom_Bult;
  7. public float speed;
  8. public float timeLim;
  9. //private float r;//半徑
  10. //private float w;//角度
  11. //private float x;
  12. //private float y;
  13. private float time;
  14. public Vector3 mov;
  15. // Use this for initialization
  16. Vector3 startpos;
  17. public GameObject effect;
  18. void Start()
  19. {
  20. //Vector3 rota = transform.eulerAngles;
  21. //rota.x = 90;
  22. //this.transform.eulerAngles = rota;
  23. mov = new Vector3(Mathf.Sin(transform.eulerAngles.y), 0, Mathf.Cos(transform.eulerAngles.y));
  24. //GetComponent<Rigidbody>().AddForce(mov);
  25. startpos = transform.position;
  26. GetComponent<Rigidbody>().AddForce(mov * speed);
  27. }
  28. // Update is called once per frame
  29. void Update()
  30. {
  31. //time += Time.deltaTime;
  32. //if (time <= timeLim)
  33. // GetComponent<Rigidbody>().AddForce(mov);
  34. //if (time > timeLim && time <= timeLim + 1)
  35. //{
  36. // GetComponent<Rigidbody>().velocity = Vector3.zero;
  37. //}
  38. //if (time > timeLim + 1)
  39. //{
  40. //}
  41. if(Vector3.Distance(startpos,transform.position)>20)
  42. Destroy(gameObject);
  43. }
  44. void OnTriggerEnter(Collider col)
  45. {
  46. if (col.CompareTag("Player"))
  47. {
  48. col.SendMessage("TakeDamage",5);
  49. Instantiate(effect, transform.position, Quaternion.identity);
  50. Destroy(this.gameObject);
  51. }
  52. if (col.CompareTag("Floor"))
  53. {
  54. Instantiate(effect, transform.position, Quaternion.identity);
  55. Destroy(this.gameObject);
  56. }
  57. }
  58. }