菜鸟专用
简单移动和跳跃(可添加音乐脚步)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlaterControl : MonoBehaviour
{
//刚体
private Rigidbody rBody;
//是否在地面上
private bool isGround;
//音频组件
private AudioSource footPlayer;
void Start()
{
//获得刚体
rBody = GetComponent<Rigidbody>();
//获取声音组件
footPlayer = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
//如果按下空格键2.角色在地面上
if(Input .GetKeyDown (KeyCode.Space )&&isGround ==true )
{
//跳跃:给一个向上的力
rBody.AddForce(Vector3.up * 200);
}
//是否按下移动键
float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis("Vertical");
//一定按了移动按键并且角色在地面上
if((horizontal !=0 || vertical !=0)&&isGr