using System.Collections; using System.Collections.Generic; using UnityEngine; public class BulletMove : MonoBehaviour { //定义变量 public float MoveSpeed; public GameObject explode; // Use this for initialization void Start () { //找到爆炸特效的预设物 explode = Resources.Load("Prefabs/Explode"); } // Update is called once per frame void Update () { //子弹移动 transform.Translate(Vector3.back*MoveSpeed*Time.deltaTime); } private void OnTriggerEnter(Collider other) { //碰撞检测 当子弹碰到tag为stone的物体时 生成爆炸特效预设物 摧毁石头 摧毁子弹 加分 if (other.tag=="stone") { GameObject go = Instantiate(explode); go.transform.position = other.transform.position; Destroy(other.gameObject); Destroy(this.gameObject); ScoreManager.instance.Score += 10; } } }