Mini-Games-Game/Assets/Movement.cs
Santi 3ffb61b5a9 Unity: Pickable Objects & Prototype Textures
Objects tagged with PickableObjects can be picked up by the player. The object is moved above the player's head, multiple objects cannot be picked up and objects can be placed down again

Added textures from the Unity Asset Store For Testing Grounds
2024-04-28 15:08:27 +01:00

49 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float speed = 5.0f;
public float sprintSpeed = 10.0f;
public float jumpForce;
public float gravity = 9.8f;
private CharacterController controller;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if (Input.GetKey(KeyCode.LeftShift))
{
moveDirection *= sprintSpeed;
jumpForce = 4.0f;
}
else
{
moveDirection *= speed;
jumpForce = 2.5f;
}
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpForce;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}