Hello im just making a game that is VERY simple and im really really new to this. Im coding in c# and i want to make a jump script where the cube just stands still and jumps. I dont know what to write in the code. I tried to do somethings but it didnt work as intended. I guess you could use this to help me and maybe ill learn. I also havent set up to check if its touching the ground, i was just trying to find a way to make it jump first then ill do that.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
//Spawn Variables
public float playerSetX;
public float playerSetY;
public float playerSetZ;
//Movement Variables
public float playerJumpHeight = 2;
void Start () {
//Player Spawn Point
//This is where our player will start when the game is played.
//player == game object. Game object == transform!
transform.position = new Vector3(playerSetX, playerSetY, playerSetZ);
}
void Update () {
//player to move up jumping
//player (gameobject) aka transform to move when i press the arrow keys or keyboard keys
//jump
if (Input.GetKeyDown (KeyCode.A) || Input.GetKeyDown (KeyCode.D) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.Space) || Input.GetKeyDown (KeyCode.UpArrow)) {
transform.position += new Vector3(playerSetX, playerJumpHeight, playerSetZ);
}
}
}
↧