Error CS0246: The type or namespace name 'ChallengeController' could not be found.
I have been following a tutorial on how to create a 2D Endless Runner, however I got stuck in an Error. I have been following this tutorial. In the minute 0:41:00 he writes a variable "ChallengeController myChallengeController;" and whenever I write that I get error CS:0246 and the text "ChallengeController" turns red.
This is my current Scene (Dropbox download link).
These are my Scripts:
PlayerScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour {
public float jumpPower = 10.0f;
Rigidbody2D myRigidbody;
bool isGrounded = false;
float posX = 0.0f;
bool isGameOver = false;
ChallengeController myChallengeController;
// Use this for initialization
void Start () {
myRigidbody = transform.GetComponent<Rigidbody2D>();
posX = transform.position.x;
myChallengeController = GameObject.FindObjectOfType<ChallengeController>();
}
void FixedUpdate () {
if (Input.GetKey(KeyCode.Space) && isGrounded && !isGameOver) {
myRigidbody.AddForce (Vector3.up * (jumpPower * myRigidbody.mass * myRigidbody.gravityScale * 20.0f));
}
//Hit in face check
if (transform.position.x < posX) {
GameOver ();
}
}
void Update() {
}
void GameOver() {
isGameOver = true;
}
void OnCollisionEnter2D(Collision2D other) {
if (other.collider.tag == "Ground") {
isGrounded = true;
}
}
void OnCollisionStay2D(Collision2D other)
{
if (other.collider.tag == "Ground") {
isGrounded = true;
}
}
void OnCollisionExit2D(Collision2D other) {
if (other.collider.tag == "Ground") {
isGrounded = false;
}
}
}
And ChallengeScroller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChallengeScroller : MonoBehaviour {
public float scrollSpeed = 5.0f;
public GameObject[] challenges;
public float frequency = 0.5f;
float counter = 0.0f;
public Transform challengesSpawnPoint;
bool isGameOver = false;
// Use this for initialization
void Start () {
GenerateRandomChallenge ();
}
// Update is called once per frame
void Update () {
if (isGameOver)
return;
//GenerateObjects
if (counter <= 0.0f) {
GenerateRandomChallenge ();
}
else {
counter -= Time.deltaTime * frequency;
}
//Scrolling
GameObject currentChild;
for (int i = 0; i < transform.childCount; i++) {
currentChild = transform.GetChild(i).gameObject;
ScrollChallenge(currentChild);
if (currentChild.transform.position.x <= -30.0f) {
Destroy (currentChild);
}
}
}
void ScrollChallenge(GameObject currentChallenge) {
currentChallenge.transform.position -= Vector3.right * (scrollSpeed * Time.deltaTime);
}
void GenerateRandomChallenge() {
GameObject newChallenge = Instantiate (challenges [Random.Range (0, challenges.Length)], challengesSpawnPoint.position, Quaternion.identity) as GameObject;
newChallenge.transform.parent = transform;
counter = 1.0f;
}
public void GameOver() {
isGameOver = true;
}
}
I will really appreciate any help, Thanks everyone!
Your answer
Follow this Question
Related Questions
Player cannot double jump 1 Answer
How can I get a player to move in one direction and around it in the same time unity 2D 1 Answer
Pause scene when character hit object, then resume it from another scene 0 Answers
stopping 1 animation and playing another 0 Answers
How to Make Game Object (Enemy) Move (Right to Left) in 2D Endless Runner Game? 0 Answers