car
This commit is contained in:
8
Assets/Character/Scripts.meta
Normal file
8
Assets/Character/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab7d5486bef4e974087db69b0c307254
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Character/Scripts/CharacterMovementCotroller.cs
Normal file
43
Assets/Character/Scripts/CharacterMovementCotroller.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class CharacterMovementCotroller : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] float driveSpeed = 10f;
|
||||
[SerializeField] float turnSpeed = 1000f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
EvaluateMovementInput();
|
||||
}
|
||||
|
||||
private Vector3 turnLeft = new Vector3(0, -1, 0);
|
||||
private Vector3 turnRight = new Vector3(0, 1, 0);
|
||||
|
||||
void EvaluateMovementInput() {
|
||||
Quaternion currentRotation = transform.rotation;
|
||||
if (Keyboard.current.wKey.isPressed) {
|
||||
Vector3 moveBy = transform.forward * driveSpeed * Time.deltaTime;
|
||||
transform.position += moveBy;
|
||||
}
|
||||
if (Keyboard.current.sKey.isPressed) {
|
||||
Vector3 moveBy = transform.forward * -1 * driveSpeed * Time.deltaTime;
|
||||
transform.position += moveBy;
|
||||
}
|
||||
if (Keyboard.current.aKey.isPressed) {
|
||||
transform.Rotate(turnLeft * Time.deltaTime * turnSpeed);
|
||||
}
|
||||
if (Keyboard.current.dKey.isPressed) {
|
||||
transform.Rotate(turnRight * Time.deltaTime * turnSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30b89096a634b634ea818091dae0462f
|
||||
Reference in New Issue
Block a user