栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

Unity作业

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity作业

												**Unity作业**

游戏名称:小球快跑

1. 场景设置
先create两个cube,我把scale设置成x为20,y和z为1,在create一个空文件,把两个cube放入,改名改成wallup和walldown。创建一个球,改成player,让scene画面处于上面为y,右面为x;然后在Game页面下面的display后面改成16:10。这样场景布置就完成了
2.简单的移动
给player设置刚体和移动,给player属性(Add Component)添加Rigbody 和script。添加完之后在Rd的位置选player再利用c#来实现player的移动,代码如下:using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMove : MonoBehaviour {
public float speedAutoMove = 5;
public float speedMoveUpAndDown = 20;
public Rigidbody rd;
// Use this for initialization
void Start () {
rd = gameObject.GetComponent();
}

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

    PlayerAutoMove();
    PlayerMoveUpAndDown();

}
private void PlayerAutoMove()
{
    rd.AddForce(Vector3.right * speedMoveUpAndDown);
}
private void PlayerMoveUpAndDown()
{
    float v = Input.GetAxis("Vertical");
    rd.AddForce(v * speedMoveUpAndDown * Vector3.up);
}

}
在进行wall的设置,还是利用c#来实现,代码如下:using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WallControl : MonoBehaviour {
private float offset;
public GameObject player;

// Use this for initialization
void Start () {
    offset = gameObject.transform.position.x - player.transform.position.x;
    
}
void Update()
{
    FollowPlayerMove();
}

// Update is called once per frame
void FollowPlayerMove () {
    gameObject.transform.position = new Vector3(player.transform.position.x+offset,0,0);
}

}
再设置camera,实现相机跟随,用c#代码如下:using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour {
public GameObject player;
private float offset;
// Use this for initialization
void Start () {
offset = gameObject.transform.position.x - player.transform.position.x;
}

// Update is called once per frame
void Update () {
    gameObject.transform.position = new Vector3(offset+ player.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
}

}
还可以在project的空白处创建material,添加颜色用来更好的区分。
设置障碍物
把player的Cube(Mesh Filter)的Mesh改成Cube,随机建立障碍物
做完这些的截图,未完待续!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/901588.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号