BulletMove.cs 985 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BulletMove : MonoBehaviour {
  5. //定义变量
  6. public float MoveSpeed;
  7. public GameObject explode;
  8. // Use this for initialization
  9. void Start () {
  10. //找到爆炸特效的预设物
  11. explode = Resources.Load<GameObject>("Prefabs/Explode");
  12. }
  13. // Update is called once per frame
  14. void Update () {
  15. //子弹移动
  16. transform.Translate(Vector3.back*MoveSpeed*Time.deltaTime);
  17. }
  18. private void OnTriggerEnter(Collider other)
  19. {
  20. //碰撞检测 当子弹碰到tag为stone的物体时 生成爆炸特效预设物 摧毁石头 摧毁子弹 加分
  21. if (other.tag=="stone")
  22. {
  23. GameObject go = Instantiate(explode);
  24. go.transform.position = other.transform.position;
  25. Destroy(other.gameObject);
  26. Destroy(this.gameObject);
  27. ScoreManager.instance.Score += 10;
  28. }
  29. }
  30. }