41308人加入学习
(116人评价)
Unity零基础入门 - 打砖块(Unity 2017) - 旧版
价格 免费

creat new c#,named Movement,add Movement 到相机组件

float h=Input.GetAxis("Horizontal");

Debug.Log("h");

transform.Translate(new Vetor3(h,0,0));

 

//

transform.Translate(new Vetor3(h,0,0)*Time.deltaTime);

 

 

//

public float speed=3;

transform.Translate(new Vetor3(h,0,0)*Time.deltaTime*speed);

[展开全文]

获取键盘输入值(方向键或WASD),浮点数值 float h = Input.GetAxis("Horizontal");

修改位置属性,值为刚刚的浮点数值 transform.Translate(new Vector3(h, 0, 0));

当前帧的时间间隔(大概1/50)Time.deltaTime

[展开全文]

Movement//控制相机移动

float h = Input.GetAxis("Horizontal");

Debug.Log(h);

transform.Translate(new Vector3(h, 0, 0));

Time.deltTime

[展开全文]

控制摄像机左右移动

为摄像机移动添加一个新的脚本Movement

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript2 : MonoBehaviour
{
    public float speed = 3;
    // Start is called before the first frame update
    void Start()
    {
       
    }
    // Update is called once per frame
    void Update()
    {
       float h= Input.GetAxis("Horizontal");
        //Debug.Log(h);按左返回负值
        transform.Translate(new Vector3(h,0,0)*Time.deltaTime*speed);
    }
}
[展开全文]

授课教师

SiKi学院老师

课程特色

图文(2)
下载资料(1)
视频(19)