I am a Beginner and just started learning Unity 2 weeks ago.
I am Trying to Create just the Player Movement by my own…
My Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public Transform t;
// Start is called before the first frame update
void Start()
{
rb.velocity = new Vector3(0, 1 ,0);
}
// Update is called once per frame
void Update()
{
//Movement code
if(Input.GetKey(KeyCode.Space))
{
rb.velocity = new Vector3(0, 5, 0);
}
if(rb.velocity.z > 5)
{
rb.velocity = new Vector3(0, 0, 0);
}
if(Input.GetKey(KeyCode.W))
{
rb.velocity = new Vector3(0, 0, 5);
}
if(Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector3(-5, 0, 0);
}
if(Input.GetKey(KeyCode.S))
{
rb.velocity = new Vector3(0, 0, -5);
}
if(Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector3(5, 0, 0);
}
//THE CODE I HAVE ERROR:
if(Input.GetKey(KeyCode.C))
{
t.localScale = new localScale(1, 0.6, 1);
}
}
}
pls help
thx" it worked
– ytrytr1929