Instructions
Have a single player controlled by a WASD controller that has elements that interacts with simple triggers.
Due on Feb 3, 2025, 12:30 PM
Finished building codes for key “W” in class, here is the complete code with the rest of A,S,D.
using UnityEngine;
public class WASD_Controller : MonoBehaviour
{
public float moveSpeed = 0.1f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
Debug.Log("Hellow World");
}
// Update is called once per frame
void Update()
{
Debug.Log("Over and Over");
Vector3 position = transform.position;
// If player pressed "W" on the Keyboard, Print W in Console.
if(Input.GetKey(KeyCode.W))
{
position += new Vector3(0, moveSpeed, 0);
Debug.Log("W");
}
// If player pressed "S" on the Keyboard, Print S in Console.
if(Input.GetKey(KeyCode.S))
{
position += new Vector3(0, -moveSpeed, 0);
Debug.Log("S");
}
// If player pressed "A" on the Keyboard, Print A in Console.
if(Input.GetKey(KeyCode.A))
{
position += new Vector3(-moveSpeed, 0, 0);
Debug.Log("A");
}
// If player pressed "D" on the Keyboard, Print D in Console.
if(Input.GetKey(KeyCode.D))
{
position += new Vector3(moveSpeed, 0, 0);
Debug.Log("D");
}
transform.position = position;
}
}
DEMO: