SHADE_Y3/TempScriptsFolder/PlayerController.cs

53 lines
1.0 KiB
C#
Raw Normal View History

2022-10-30 23:59:35 +08:00
using SHADE;
using System;
public class PlayerController : Script
{
private RigidBody rb;
public float xAxisMove;
public float zAxisMove;
public float force = 800.0f;
public PlayerController(GameObject gameObj) : base(gameObj) { }
protected override void awake()
{
rb = GetComponent<RigidBody>();
if (rb == null)
{
Debug.LogError("RigidBody is NULL!");
}
}
protected override void update()
{
Move();
//float x = xAxisMove * force * (float)Time.DeltaTime;
//Debug.Log(x.ToString());
}
private void Move()
{
if (Input.GetKey(Input.KeyCode.A))
xAxisMove = -1;
else if (Input.GetKey(Input.KeyCode.D))
xAxisMove = 1;
else
xAxisMove = 0;
if (Input.GetKey(Input.KeyCode.W))
zAxisMove = -1;
else if (Input.GetKey(Input.KeyCode.S))
zAxisMove = 1;
else
zAxisMove = 0;
if (rb != null)
rb.AddForce(new Vector3(xAxisMove * force * (float)Time.DeltaTime, 0.0f, zAxisMove * force * (float)Time.DeltaTime));
}
}