Character Selection
Hello! I created a few characters, in which I'd like the player to choose from, I created a script which will allow the player to "scroll" through the characters using the right arrow, however, I am only able to scroll once, before it stops working.
My script is most likely very poorly made, I am rather new with C#, I put all the characters at the same location, and set them inactive, except for the first one. I made an if statement, detecting if a character was active, and the arrow has been pushed, then it will shuffle to the next character. This however didn't work, is there a better way?
Here is the Script: (Sorry for the mess)
using UnityEngine;
using System.Collections;
public class CharacterSelection : MonoBehaviour {
public GameObject BlackHairBlueShirtBluePants;
public GameObject BlackHairBlueShirtGreyPants;
public GameObject BlondeHairBlueShirtBluePants;
public GameObject BlondeHairBlueShirtGreyPants;
public GameObject BrownHairBlueShirtBluePants;
public GameObject BrownHairBlueShirtGreyPants;
public bool hair;
public bool shirt;
public bool pants;
void Start () {
BlackHairBlueShirtBluePants.SetActive(true);
BlackHairBlueShirtGreyPants.SetActive(false);
BlondeHairBlueShirtBluePants.SetActive(false);
BlondeHairBlueShirtGreyPants.SetActive(false);
BrownHairBlueShirtBluePants.SetActive(false);
BrownHairBlueShirtGreyPants.SetActive(false);
hair = true;
}
void Update()
{
hair = true;
if(Input.GetButtonDown("Interact1"))
{
if (hair)
{
hair = false;
pants = true;
}
if (pants)
{
pants = false;
shirt = true;
}
if (shirt)
{
shirt = false;
hair = true;
}
}
if (Input.GetButtonDown("Interact") && hair)
{
if(BlackHairBlueShirtBluePants.activeSelf)
{
BlackHairBlueShirtBluePants.SetActive(false);
BlondeHairBlueShirtBluePants.SetActive(true);
}
if (BlondeHairBlueShirtBluePants.activeSelf)
{
BlondeHairBlueShirtBluePants.SetActive(false);
BrownHairBlueShirtBluePants.SetActive(true);
}
if (BrownHairBlueShirtBluePants.activeSelf)
{
BrownHairBlueShirtBluePants.SetActive(false);
BlondeHairBlueShirtBluePants.SetActive(true);
}
if (BlackHairBlueShirtGreyPants.activeSelf)
{
BlackHairBlueShirtGreyPants.SetActive(false);
BlondeHairBlueShirtGreyPants.SetActive(true);
}
if (BlondeHairBlueShirtGreyPants.activeSelf)
{
BlondeHairBlueShirtGreyPants.SetActive(false);
BrownHairBlueShirtGreyPants.SetActive(true);
}
if (BrownHairBlueShirtGreyPants.activeSelf)
{
BrownHairBlueShirtGreyPants.SetActive(false);
BlondeHairBlueShirtGreyPants.SetActive(true);
}
}
if (Input.GetButtonDown("Horizontal") && pants)
{
if (BlackHairBlueShirtBluePants.activeSelf)
{
BlackHairBlueShirtBluePants.SetActive(false);
BlackHairBlueShirtGreyPants.SetActive(true);
}
if (BlackHairBlueShirtGreyPants.activeSelf)
{
BlackHairBlueShirtGreyPants.SetActive(false);
BlackHairBlueShirtBluePants.SetActive(true);
}
if (BrownHairBlueShirtBluePants.activeSelf)
{
BrownHairBlueShirtBluePants.SetActive(false);
BrownHairBlueShirtGreyPants.SetActive(true);
}
if (BrownHairBlueShirtGreyPants.activeSelf)
{
BrownHairBlueShirtGreyPants.SetActive(false);
BrownHairBlueShirtBluePants.SetActive(true);
}
if (BlondeHairBlueShirtBluePants.activeSelf)
{
BlondeHairBlueShirtBluePants.SetActive(false);
BlondeHairBlueShirtGreyPants.SetActive(true);
}
if (BlondeHairBlueShirtGreyPants.activeSelf)
{
BlondeHairBlueShirtGreyPants.SetActive(false);
BlondeHairBlueShirtBluePants.SetActive(true);
}
}
}
}
Please post your script anyway, it'll be easier to understand what you tried to achieve, and it can probably be fixed.
remove hair = true; from the update method else if (Input.GetButtonDown("Interact") && hair)
will always be true.
I dont remember if I added hair = true to the update function after my issue as an attempt to fix it, but I will try that when I get home.
Your answer
Follow this Question
Related Questions
restricting player movement with a path? 1 Answer
I want to add some Velocity controll to my CharacterController 1 Answer
fps script not working 1 Answer
Issue with Rigidbody2D (I think) 2 Answers
I have my animations created. Now what? 0 Answers