- Home /
Player switch on ui button
I have two characters each with a different controller that does different things. I want only one to be active and when you press the ui button the other one activates where the last character was. When I try use it I get the following error "UnassignedReferenceException: The variable startHelpText of switchcharacter has not been assigned you probably need to assign the startHelpText variable ofthe switchcharacter script in the inspector. startHelpText is the name of one of the characters
using UnityEngine;
using System.Collections;
public class switchcharatcer : MonoBehaviour {
public GameObject startHelpText;
public GameObject Player;
public int characterselect;
void Start()
{
startHelpText.SetActive(false);
characterselect = 1;
startHelpText = GameObject.Find("startHelpText");
Player = GameObject.Find("Player");
}
public void switchHelp()
{
if (characterselect == 1)
{
startHelpText.transform.position = Player.transform.position;
characterselect = characterselect + 1;
}
else if (characterselect == 2)
{
Player.transform.position = startHelpText.transform.position;
characterselect = 1;
}
if (characterselect == 1)
{
Player.SetActive(true);
startHelpText.SetActive(false);
}
if (characterselect == 2)
{
Player.SetActive(false);
startHelpText.SetActive(true);
}
}
Your answer
Follow this Question
Related Questions
switch player and npc follow player 0 Answers
How to switch and unlock game characters in real time 0 Answers
How to switch between different characters in real time? 0 Answers
changing player (getting in vehicles) 3 Answers
Controller Movement!! 1 Answer