版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_15153793/article/details/84542333
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletMove : MonoBehaviour {
//子弹移动速度
private float bulletTime = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.up * bulletTime * Time.deltaTime);
//当子弹超出屏幕后销毁
if (transform.position.y > 5f) {
Destroy (gameObject);
}
}
//触碰到敌机以后销毁子弹
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Enemy") {
Destroy (gameObject);
}
}
}