Hello I am trying to make a c# code for my platformer. I already have code for moving left and right, but I am trying to make one that will make the character jump. This is what I have now, but it says
"error CS0102: An object reference is required to access non static member ‘UnityEngine.Transform.TransformDirection(UnityEngine.Vector3)’ "
using UnityEngine;
using System.Collections;
public class jump_controller : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
Please keep in mind this is my 2nd script and I don’t know much about this so please keep it simple.