游戏场景预设图
玩法:使蓝色的小球触碰到黄色的开关让门降下去,并且不触碰任何东西进入下一关。
介绍:蓝色的小球是玩家,黄色的是开关用来开绿色点前面的门,红色的是障碍物,黑色的是墙。
创建场景以及绑定代码
首先搭建一个场景把地板的Plane命名为Ground并且把Tag设置为Ground。
然后创建一个Sphere命名为Player并且把Tag设置为Player,添加一个Rigidbody。
(墙只用搭建不需要做任何改动)
在Player上创建一个名为playercontroller的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class playercontroller : MonoBehaviour
{
public Rigidbody rb;//获取玩家的Rigidbody组件
public float moveForce;
Vector3 input;
Vector3 startPos;
public int nextStageIndex;//场景转换到的标签号
private void Start()
{
startPos = GetComponent<Transform>().position