Unity学习笔记之子弹发射

Angular 角速度
GetComponent().angularVelocity = Random.insideUntSphere * tumble

rigidbody component中的angular drag是角速度的空气阻力

Instantiate

Instantiate(gameObject,transform.position,transform.rotation)在游戏里生成一个gameObject,后两个参数是将要赋值给gameObject的transform和rotation
gameObject可以有自己的script,比如Start()函数里设置velocity从而给它一个初始速度。

Collider

Collider勾选isTrigger代表碰撞作为一个trigger。
相关函数示例:

void OnTriggerEnter(Collider other)
{ 
Destory(other.gameObject);
}
void OnTirggerExit(Collider other)
{
Destory(other.gameObject);
}

子弹发射的冷却时间设置

public float fireRate;
private float nextTime;
private void Update()
{
if(Input.GetButton("Fire1")&&Time.time>nextTime)
{
nextFire = Time.time+fireRate;
Instantiate(Shot,ShotSpawn.position,ShotSpawn.rotation);
}
}

你可能感兴趣的:(Unity学习笔记之子弹发射)