物体移动代码示例:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
float currentvelocity;
public float smoothtime = 0.2f;
public float walkspeed = 2f;
private Animator ac;
private Transform cameratransfrom;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
ac = this.GetComponent<Animator>();
cameratransfrom = Camera.main.transform;
rb = this.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical"));
Vector2 inputdir = input.normalized;