Error pls help
Help I don't know what i did wrong. I got this error: Assets/scripts/player.cs(81,28): error CS1061: Type Gamemaneger' does not contain a definition for
RestartGame' and no extension method RestartGame' of type
Gamemaneger' could be found (are you missing a using directive or an assembly reference?) Scripts:
Player script:
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour { public float moveSpeed; public float JumpForce;
public float jumpTime;
private float jumpTimeCounter;
private Rigidbody2D myRigidbody;
public bool grounded;
public LayerMask whatisground;
public Transform groundcheck;
public float radius;
private Collider2D mycollider;
private Animator myanimator;
public Gamemaneger theGamemanager;
// Use this for initialization
void Start () {
myRigidbody = GetComponent<Rigidbody2D>();
mycollider = GetComponent<Collider2D>();
myanimator = GetComponent<Animator>();
jumpTimeCounter = jumpTime;
}
// Update is called once per frame
void Update () {
//grounded = Physics2D.IsTouchingLayers(mycollider, whatisground);
grounded = Physics2D.OverlapCircle(groundcheck.position, radius, whatisground);
myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
{
if(grounded)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, JumpForce);
}
}
if (Input.GetKey (KeyCode.Space) || Input.GetMouseButton(0))
{
if(jumpTimeCounter > 0)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, JumpForce);
jumpTimeCounter -= Time.deltaTime;
}
}
if(Input.GetKeyUp (KeyCode.Space) || Input.GetMouseButtonUp(0))
{
jumpTimeCounter = 0;
}
if(grounded)
{
jumpTimeCounter = jumpTime;
}
myanimator.SetFloat("snelheid", myRigidbody.velocity.x);
myanimator.SetBool("Grounded", grounded);
}
void OnCollisionEnter2D (Collision2D other)
{
if(other.gameObject.tag == "killbox")
{
theGamemanager.RestartGame();
}
}
}
Gamemaneger script:
using UnityEngine; using System.Collections; using System;
public class Gamemaneger : MonoBehaviour {
public Transform Platformgenerator;
private Vector3 platformStartpoint;
public player thePlayer;
private Vector3 playerStartPoint;
// Use this for initialization
void Start () {
platformStartpoint = Platformgenerator.position;
playerStartPoint = thePlayer.transform.position;
}
// Update is called once per frame
void Update ()
{ }
public void RestartGame()
{
StartCoroutine(RestartGameCo());
}
public IEnumerator RestartGameCo()
{
thePlayer.gameObject.SetActive(false);
yield return new WaitForSeconds(0.5f);
thePlayer.transform.position = playerStartPoint;
Platformgenerator.position = platformStartpoint;
thePlayer.gameObject.SetActive(true);
}
}
The error is on line 81 of Player.cs except you seem to have no line 81 in Player.cs so I guess you have other issues to fix first.
I am guessing error is actually at line 74 within the code pasted.
Answer by whalan84 · Jan 10, 2016 at 03:34 PM
Remembering I am only a beginner and I may be leading you astray here but as the Gamemaneger variable on line 16 is a public variable, try going to the unity inspector window for which ever object the 'player (script)' component is attached to and click the small circle next to 'Gamemaneger' and select an item which has the Gamemaneger script attached.