NGUI————按钮练习题
1.几个注意点,看图
代码:
坦克:
public class Tank : MonoBehaviour
{public Transform shootPoint;void Start(){Fire();}public void Fire(){Instantiate(Resources.Load("bullet"),shootPoint.position,shootPoint.rotation);}
}
子弹:
public class bullet : MonoBehaviour
{public float moveSpeed = 20f; //子弹移动速度void Start(){Destroy(this.gameObject, 3);}void Update(){this.transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);}
}
面板:
public class GamePanel : MonoBehaviour
{public Tank tank;public UIButton btn;void Start(){btn.onClick.Add(new EventDelegate(() =>{tank.Fire();}));}
}
效果: