PlayerController and PickAndThrow #167

Merged
glencelow merged 21 commits from PlayerController into main 2022-11-02 17:40:51 +08:00
1 changed files with 52 additions and 0 deletions
Showing only changes of commit 7a6474eaf8 - Show all commits

View File

@ -0,0 +1,52 @@
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));
}
}