子弹预制体:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Zidan : MonoBehaviour
{
//这个脚本绑定到对象
//对象多了一个rbody参数,不是public,这个参数的值由Awake脚本调用的时候start之前赋予。
Rigidbody2D rbody;
// Start is called before the first frame update
void Awake()
{
rbody = this.GetComponent<Rigidbody2D>(); //从对象获取刚体赋值给参数
Destroy(this.gameObject, 2f); //多长时间消失
}
//子弹移动
public void ZiDanMove(Vector2 FangXiang , float LiLiang)
{
rbody.AddForce(FangXiang * LiLiang);
}
}
盒子(生产和操控子弹):
using System.Collections