hi to all! I got this error (CS0162 C# Unreachable code detected) but I don't get why...
this is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GamecontrollerBeha : MonoBehaviour
{
public bool invent, invsaver, oggetto1, oggetto2, oggetto3, ogg1sel, ogg2sel, ogg3sel, mangiato, lavato, vestito;
public GameObject inv, ogg1, ogg2, ogg3;
private GameObject canvfind;
public static GamecontrollerBeha instance;
public Transform invspawn;
public string savefile;
public string SaveToString()
{
return savefile = JsonUtility.ToJson(this);
PlayerPrefs.GetString(savefile); /**** <- ERROR happening HERE ****/
}
void Awake()
{
if (instance == null)
{
DontDestroyOnLoad(gameObject);
instance = this;
}
else if (instance != this)
{
Destroy(gameObject);
}
}
public void Start()
{
gameObject.tag = "gamecontroller";
}
public void Update()
{
canvfind = GameObject.FindGameObjectWithTag("canvas");
if (Input.GetKeyDown("space"))
{
Vector3 spawncorrector = new Vector3(invspawn.position.x, invspawn.position.y - 1, 0);
Vector3 spawncorrector1 = new Vector3(invspawn.position.x - 2.3F, invspawn.position.y - 0.5F, -1);
Vector3 spawncorrector2 = new Vector3(invspawn.position.x - 2.3F, invspawn.position.y - 1.5F, -1);
Vector3 spawncorrector3 = new Vector3(invspawn.position.x - 2.3F, invspawn.position.y - 0.5F, -1);
if (invsaver == false)
{
if (invent == true)
{
invent = false;
Destroy(GameObject.FindWithTag("inventario"));
Destroy(GameObject.FindWithTag("oggetto1"));
Destroy(GameObject.FindWithTag("oggetto2"));
Destroy(GameObject.FindWithTag("colazione"));
}
else if (invent == false)
{
GameObject inve = Instantiate(inv, spawncorrector, invspawn.rotation);
inve.transform.SetParent(canvfind.transform);
invent = true;
if (oggetto1 == true)
{
GameObject og1 = Instantiate(ogg1, spawncorrector1, invspawn.rotation);
og1.transform.SetParent(canvfind.transform);
}
if (oggetto2 == true)
{
GameObject og2 = Instantiate(ogg2, spawncorrector2, invspawn.rotation);
og2.transform.SetParent(canvfind.transform);
}
if (oggetto3 == true)
{
GameObject og3 = Instantiate(ogg3, spawncorrector3, invspawn.rotation);
og3.transform.SetParent(canvfind.transform);
}
}
}
}
}
}
thanks from now for the help!
↧