Unity3d打飞机(二)子弹的移动与销毁

分类栏目:unity3d教程

177

Unity3d(二)子弹的移动与销毁


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);
		}
	}
}