首先新建出一个场景,加入平台,弹珠,以及操控的对象
随后给他们写入脚本
写入脚本首先是操控对象的移动。这里我们使用这一段代码进行实现:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public Rigidbody rg;
// Start is called before the first frame update
void Start()
{
rg = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
rg.AddForce(new Vector3(h,0,v));
}
}
经过这一串代码,我们的对象就可以实现基本的移动了。随后我们添加上碰撞效果,以及跳跃效果,这次我们使用这一串代码来实现:
这是碰撞效果的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public