Unity3D2017_1_打砖块游戏

操作效果
Alt+鼠标左键以物体为中心,转动观察
选中物体ctrl+D直接复制这个物体
按住ctrl移动物体按指定方向移动一个单位
Input.GetMouseButtonDown(0)检测是否鼠标按下
b.GetComponent()获得刚体组件Rigidbody
transform.forward对象正向方向
GameObject.Instantiate(bullet, transform.position, transform.rotation)实例化对象
rgb.velocity刚体组件速度
transform.Translate(new Vector3(x, y, 0) * Time.deltaTime * speed )控制物体移动

Material

在这里插入图片描述

  • Albedo 选择颜色
  • Metallic 金属质感程度
  • Smoothness 光滑度
  • 前面的小圆圈点击可以选择贴图

脚本

控制相机移动
public class Movement : MonoBehaviour {

    public float speed = 3;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");
        // Translate()控制方向移动
        // Vector(),如果你一直按着右键,每一帧移动1米,1s有几十帧
        // Time.deltaTime时间间隔,每秒
        transform.Translate(new Vector3(x, y, 0) * Time.deltaTime * speed );
	}
}
控制射击
public class Shoot : MonoBehaviour {

    public GameObject bullet;
    public float speed = 5f;

	// Use this for initialization
	void Start () {

        
	}
	
	// Update is called once per frame
	void Update () {

        if ( Input.GetMouseButtonDown(0))// 检测是否鼠标按下,0代表带是鼠标左键
        {
            //instantiate a GameObject bullet,transform代表的是当前对象的transform组件
            //这里获得了cinema的position和rotation
            GameObject b = GameObject.Instantiate(bullet, transform.position, transform.rotation);
            Rigidbody rgb = b.GetComponent<Rigidbody>();//获得刚体组件Rigidbody
            rgb.velocity = transform.forward * speed;//forward意味着z轴为1,xy为0
             
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值