Need help with error CS0029 and error CS0118
Im only a rookie to scripts (C+) and i found myself stuck in these two scripts that i couldn't run in unity 3D.
These are errors it's showing:
Assets/Game/Scripts/KillPlayer.cs(20,17): error CS0029: Cannot implicitly convert type
string' to
bool'Assets/Game/Scripts/KillPlayer.cs(10,49): error CS0118:
KillPlayer.levelManager' is a
field' but a `type' was expected
I would be thankful if you would note my mistakes!
KillPlayer script:
using UnityEngine;
using System.Collections;
public class KillPlayer : MonoBehaviour {
public LevelManager levelManager;
// Use this for initialization
void Start () {
levelManager = FindObjectOfType<levelManager>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.name = "Player")
{
levelManager.RespawnPlayer();
}
}
}
LevelManager script:
using UnityEngine;
using System.Collections;
public class LevelManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void RespawnPlayer()
{
Debug.Log ("Respawn Player");
}
}
Thanks for possibly answering my question.
You pasted Level$$anonymous$$anager twice, please edit and provide the code for $$anonymous$$illPlayer.
Answer by bubzy · Jan 04, 2016 at 05:59 PM
if (other.name = "Player")
should be
if (other.name == "Player")
where you use FindObjectOfType
the syntax is incorrect
read : http://docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html
also take note of the line
Please note that this function is very slow. It is not recommended to use this function every frame. In most cases you can use the singleton pattern instead.
you might want to look at http://docs.unity3d.com/ScriptReference/GameObject.FindWithTag.html
hope this helps in some way
Answer by vintar · Jan 04, 2016 at 05:55 PM
Should be :
levelManager = FindObjectOfType ();
if (other.name == "Player")
Your answer
Follow this Question
Related Questions
Particle System trigger script not working,Particle system trigger script not working 0 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Referencing and Executing Script Can't Be Done due to Not Being A Statement 0 Answers
The namespace 'global::' already contaiins a definition for 'NewBehaviourScript' 0 Answers