1.0代表鼠标左键
1.0代表鼠标左键
//通过bullet访问到我们的预制体子弹
访问所要控制的物品
public GameObject bullet,
字段赋值
将预制体球体拖到main camera下的bullet
识别字段
GameObject.Instantiate (bullet)
//实例化子弹
GameObject.Instantiate (bullet);
//子弹位置设置
GameObject.Instantiate (bullet,transform
.positiontransform.rotation);
transform访问的是当前脚本所在物体的stansform组件,即当前脚本是shoot,shoot在main camera上,访问main camera的stransfor.position就可以使用main camera的位置信息
//按下鼠标左键才实例化
viod Update(){
if(Input.GetMouseButonDown(0))
{
GameObject.Instantiate (bullet,transform
.positiontransform.rotation);
}
}
这里没吃通, copy和预制体还有待学习;
加组件没学会
老师不练练英语吗?单词发音太难受了
胃口王嘉尔我觉得KajIAJR比我家 见覅金融街 刚给提供退热死哦人口及消费观念你那句侧uiirurtghgnbopkvfvj
实例化:GameObject.Instantiate();
位置、旋转参数:
transform.position
transform.rotation
检测鼠标按下左键:
input.GetMonseButtonDonw(0)
void start里面执行一次
void Update里面执行重复
注意要先创建空项目,把脚本套在空项目上,不然直接在场景中放小球hui
prefabs yu she
Materials
scenes
scripts
拖动SPHERE为Bullet赋值
//Input.GetMouseButtonDown为检测鼠标状态,0为左键
if(Input.GetMouseButtonDown(0))
{
// Instantiate可以实例化目标,脚本shoot为相机的组件,所以transform.position代表指定位置为当前相机位置,第三个为旋转
GameObject.Instantiate(bullet, transform.position, transform.rotation);
}
子弹实例化
public class Movement : MonoBehaviour
{
public GameObject bullet;//一定要确保bullet赋值了,在unity里面赋值
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))//按下鼠标左键实例化
{
GameObject.Instantiate(bullet, transform.position, transform.rotation);//实例化一个子弹
}
}
}