unity滚动的小球

首先在Assets文件夹下建立新的三个文件夹,便于分类ide

把camera的Allow HDR勾选框取消并调整到合适角度this

新建一个Plane,放大到两倍大小,更名为Ground,附上材质spa

建立一个空物体,在里面建立四面“墙”3d

添加一个cobe,坐标(0,1,0),缩小到1/2,更名为PickUp,附上材质orm

添加一个tag和Rigidbodyblog

    

    

写方块转动脚本it

this.transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);io

将建立的方块都存放在PickUps里form

建立玩家小球,更名为Player,tag设置成Player,添加Rigidbodyclass

编写一个使小球能够被玩家控制从而运动的脚本

void Start () {

        rb = GetComponent<Rigidbody>();

         }

     void FixedUpdate()

    {

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

        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);

        rb.AddForce(movement * speed);

 

 

}

给小球一个speed,就能够移动了,添加使小方块碰到便消失的脚本

void OnTriggerEnter(Collider other)

    {

        if (other.gameObject.CompareTag("PickUp"))

        {

            other.gameObject.SetActive(false);

        }

    }

要使摄像机能够跟着小球视角移动

void Start()

    {

        offset = this.transform.position - player.transform.position;

    }

        void LateUpdate()

        {

            this.transform.position = player.transform.position + offset;

        }

增长两个文字提示text

相关文章
相关标签/搜索