I have this error on line 38 of the script below.I know that there were some other questions of the same type.But none was helpful to me.This error have stopped my project.And I want to get rid of it quickly.So, if someone could help me i would be greatly thakful.Here is my code
using System.Collections.Generic;
using UnityEngine;
public class LootChest : MonoBehaviour
{
public int MaxItems;
int ItemCount;
List<Item> Items = new List<Item>();
public GameManager GameManager;
bool Selected;
public float Distance;
public Color HoverColour;
public Color ClickColour;
Color DefaultColor;
// Use this for initialization
void Start()
{
ItemCount = Random.Range(0, MaxItems);
for (int i = 0; i < ItemCount; i++)
{
int r = Random.Range(0, GameManager.Instance.AllItems.Count - 1);
Items.Add(GameManager.Instance.AllItems[r]);
}
DefaultColor = GetComponent<Renderer>().material.color;
}
// Update is called once per frame
void Update()
{
}
void OnMouseOver()
{
if (Vector3.Distance(transform.position, GameManager.Instance.CurrentCharacter.Instance.transform.position) > Distance);
GetComponent<Renderer>().material.color = HoverColour;
}
void OnMouseExit()
{
if (Vector3.Distance(transform.position, GameManager.Instance.CurrentCharacter.Instance.transform.position) < Distance) ;
GetComponent<Renderer>().material.color = DefaultColor;
}
void OnMouseDown()
{
}
void OnMouseUp()
{
}
}
The error is on line
if (Vector3.Distance(transform.position, GameManager.Instance.CurrentCharacter.Instance.transform.position) < Distance) ;
This error dont show up in the script editor(Visual studio 2017).And I think this is a unity based error not script based. This is the image of unity with the cube object .
Here is the GameManager script
using UnityEngine;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public List<Character> Characters = new List<Character>();
public List <Item> AllItems = new List<Item> ();
bool ShowCharWheel;
public int SelectedCharacter;
int LastCharacter;
public static GameManager Instance;
public bool CanShowSwitch = true;
public Character CurrentCharacter;
public LootChest SelectedChest;
void Awake()
{
foreach (Character c in Characters)
{
c.Instance = Instantiate(c.PlayerPrefab, c.HomeSpawn.position, c.HomeSpawn.rotation) as GameObject;
c.Instance.GetComponent <PlayerController> ().LocalCharacter = c;
}
ChangeCharacterStart(Characters[PlayerPrefs.GetInt("SelectedChar")]);
}
// Use this for initialization
void Start()
{
}
void ChangeCharacterStart(Character c)
{
LastCharacter = SelectedCharacter;
SelectedCharacter = Characters.IndexOf(c);
CurrentCharacter = c;
Characters [LastCharacter].Instance.GetComponent<PlayerController> ().CanPlay = false;
Characters[SelectedCharacter].Instance.GetComponent<PlayerController>().CanPlay = true;
Camera.main.GetComponent<asd>().target = Characters[SelectedCharacter].Instance.transform;
PlayerPrefs.SetInt("SelectedChar", SelectedCharacter);
}
// Update is called once per frame
void Update()
{
if (CanShowSwitch) {
if (Input.GetKey (KeyCode.C)) {
ShowCharWheel = true;
} else if (Input.GetKey (KeyCode.V)) {
ShowCharWheel = false;
}
}
}
void ChangeCharacter(Character c)
{
c.Instance.GetComponent<AI> ().DoneHome = false;
if (Vector3.Distance (Characters [SelectedCharacter].Instance.transform.position, c.Instance.transform.position) > 10) {
sequencemanager.Instance.StartCoroutine ("DoCharSwitch", c);
CanShowSwitch = false;
LastCharacter = SelectedCharacter;
SelectedCharacter = Characters.IndexOf (c);
CurrentCharacter = c;
Characters [LastCharacter].Instance.GetComponent<PlayerController> ().CanPlay = false;
Characters [SelectedCharacter].Instance.GetComponent<PlayerController> ().CanPlay = true;
PlayerPrefs.SetInt ("SelectedChar", SelectedCharacter);
} else {
LastCharacter = SelectedCharacter;
SelectedCharacter = Characters.IndexOf(c);
CurrentCharacter = c;
Characters [LastCharacter].Instance.GetComponent<PlayerController> ().CanPlay = false;
Characters [SelectedCharacter].Instance.GetComponent<PlayerController> ().CanPlay = true;
PlayerPrefs.SetInt ("SelectedChar", SelectedCharacter);
Camera.main.GetComponent<asd> ().target = Characters [SelectedCharacter].Instance.transform;
}
}
void OnGUI()
{
if (ShowCharWheel)
{
GUILayout.BeginArea(new Rect(Screen.width - 64, Screen.height - 256, 64, 208), GUIContent.none, "box");
foreach (Character c in Characters)
{
if (GUILayout.Button(c.Icon, GUILayout.Width(64), GUILayout.Height(64)))
{
ChangeCharacterStart(c);
}
}
GUILayout.EndArea();
}
}
}
[System.Serializable]
public class Character
{
public string Name;
public Texture2D Icon;
public GameObject PlayerPrefab;
public GameObject Instance;
public Transform HomeSpawn;
}
[System.Serializable]
public class Item
{
public string Name;
public Texture2D Icon;
public ItemInstance InstancePrefab;
}