So I’m figuring out unity by just going in and searching up whatever i don’t understand, and im trying to avoid tutorials. Maybe that’s a bad idea, but following tutorials is boring.
I’m making a 2d character controller, and i’m implementing a thing that will check if you’re on a platform so you can jump. the jump checker itself works, but i cannot get my player controller to get the variable from the other script.
The error message i’m getting is PlayerController.cs(14,5): error CS0246: The type or namespace name ‘CanJump’ could not be found (are you missing a using directive or an assembly reference?)
also apologies in advance for my probably terrible code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public float MoveSpeed;
public float MaxSpeed;
public float JumpHeight;
GameObject JumpCheck;
CanJump Jumpable;
// Start is called before the first frame update
void Start()
{
GameObject JumpCheck = GameObject.Find("JumpCheck");
}
// Update is called once per frame
void Update()
{
Jumpable = JumpCheck.GetComponent<CanJump>();
//move left
if(Input.GetKey(KeyCode.A) | Input.GetKey(KeyCode.LeftArrow))
{
myRigidbody.velocity = myRigidbody.velocity + Vector2.left*MoveSpeed * Time.deltaTime;
if (MoveSpeed > MaxSpeed) {MoveSpeed=MaxSpeed;}
}
//jump
if(Input.GetKey(KeyCode.W) | Input.GetKey(KeyCode.Space) | Input.GetKey(KeyCode.UpArrow) && Jumpable==true)
{
myRigidbody.velocity = myRigidbody.velocity + Vector2.up*JumpHeight * Time.deltaTime;
}
//move right
if(Input.GetKey(KeyCode.D) | Input.GetKey(KeyCode.RightArrow))
{
myRigidbody.velocity = myRigidbody.velocity + Vector2.right*MoveSpeed * Time.deltaTime;
if (MoveSpeed < -MaxSpeed) {MoveSpeed = -MaxSpeed;}
}
}
}
What am i doing wrong?