Unity制作Roll-a-Ball游戏

,DirectionalLight的效果由Rotation决定而不是Position。

创建了新的object一定要先reset。

FrameSelected用于将摄像机对准某个object。

想要object有力的效果或是匀速移动,或识别撞击(Collider/Trigger),需对其添加rigidbody组件,同时编写的相关程序脚本也在相应object中添加。

左右运动在X轴,前后运动在Z轴。

使小球运动的代码:

public class playercontroller : MonoBehaviour {
public float speed;/**这个选项可以在player的Inspector中输入*/
void FixedUpdate()/**与物理相关的代码卸载这个方法里*/
{
    float moveHorizontal = Input.GetAxis ("Horizontal");/**水平方向的移动输入,左右*/
    float moveVertical = Input.GetAxis ("Vertical");/**垂直方向上的移动输入,前后*/
Vector3 movement = new Vector3 (moveHorizontal, 0.0f,moveVertical);/**movement中存放了各方向上移动的数据*/
    GetComponent<Rigidbody>().AddForce(movement*speed*Time.deltaTime);/*通过movement做参数,决定了施加力的方向和大小*/
}
}

建立摄像机与小球间联系的代码:

public class CameraContrlloer : MonoBehaviour {
public GameObject player;
priv
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值