I have been working on a mounting code and it works great now the only issue that is left is the fact that every time I mount I create a new mount and the old one is never deleted. How do I am really new to this spawning Idea and don’t understand the code fully yet could some one help me with how to delete it in my if(isMounted == true) area here is the code.
using UnityEngine;
using System.Collections;
public class GUIandSpawn : MonoBehaviour
{
private string button1Text;
public GUISkin Location1Button;
public Transform thisChar;
public Transform hoverBoard;
public GameObject prefabToSpawn;
public Transform spawn;
public bool isMounted = false;
public int dist = 1;
void OnGUI()
{
GUI.skin = Location1Button;
if(isMounted == true)
{
if (GUI.Button(new Rect(350, 100, 65, 65),button1Text))
{
thisChar.GetComponent<ThirdPersonController>().enabled = true;
thisChar.GetComponent<ThirdPersonCamera>().enabled = true;
thisChar.transform.parent = null;
isMounted = false;
}
}
if(isMounted == false)
{
if (GUI.Button(new Rect(350, 100, 65, 65),button1Text))
{
Vector3 v3Pos = thisChar.position - transform.up * dist;
GameObject clone = Instantiate(prefabToSpawn,spawn.position, spawn.rotation)as GameObject;
thisChar.transform.parent = clone.transform;
thisChar.GetComponent<ThirdPersonController>().enabled = false;
thisChar.GetComponent<ThirdPersonCamera>().enabled = false;
clone.GetComponent<HoverBoards>().enabled = true;
isMounted = true;
}
}
}
}