I cant call function another script !
Hi guys , i have bool (isFire,isWater...) and i cannot call the inside the ConfirmButton function boolean variables in the ArenaBackground class. Boolean variables seems false all the time.
Could you help me ?
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;
namespace S3{
public class CharacterSelection : MonoBehaviour {
private GameObject[] characterList;
private int index;
//Character
public bool isFire;
public bool isWater;
public bool isEarth;
public bool isWood;
private void Start(){
index = PlayerPrefs.GetInt ("CharacterSelected");
characterList = new GameObject[transform.childCount];
foreach (Transform t in transform) {
//fill the array our models
for (int i = 0; i < transform.childCount; i++) {
characterList [i] = transform.GetChild (i).gameObject;
}
//we toggle of their renderer
foreach (GameObject go in characterList) {
go.SetActive (false);
}
//toggle on the selected character
if (characterList [index])
characterList [index].SetActive (true);
}
} //Start function end
public void ToggleBack(){
SceneManager.LoadScene ("GTGD S3");
}
public void ToggleLeft(){
characterList [index].SetActive (false);
index--;
if (index < 0) {
index = characterList.Length - 1;
}
characterList [index].SetActive (true);
} // Toggle Left End
public void ToggleRight(){
characterList [index].SetActive (false);
index++;
if (index == characterList.Length) {
index =0;
}
characterList [index].SetActive (true);
}
public void ConfirmButton(){
PlayerPrefs.SetInt ("CharacterSelected", index);
SceneManager.LoadScene ("LevelTry");
if (index == 0) {
isFire = true;
Debug.LogFormat ("Fire");
} else if (index == 1) {
isWater = true;
Debug.LogFormat ("Water");
} else if (index == 2) {
isEarth = true;
Debug.LogFormat ("Earth");
} else if (index == 3) {
isWood = true;
Debug.LogFormat ("Wood");
}
}
}
}
And , my secondary script
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
namespace S3{
public class ArenaBackground : MonoBehaviour {
public CharacterSelection arenaBG;
// Use this for initialization
void Start () {
arenaBG = gameObject.AddComponent<CharacterSelection>();
if (arenaBG.isFire) {
Debug.LogFormat ("Yes !");
}
else{
Debug.LogFormat("No !");
}
}
}
}
Answer by Pengocat · Dec 13, 2016 at 01:41 AM
If you call ConfirmButton() isFire would be set to true by default and the rest to false. Since it is a public method and you add CharacterSelection while storing a reference in ArenaBackground you should be able to call the method.
hi , firstly thank you for answer.
I called ConfirmButton() in ArenaBackground ( in void Start() )
but all time (true or false) run " Debug.LogFormat ("Yes !"); "
i make a big mistake but i don't see this.
Your answer
Follow this Question
Related Questions
Why does my Gem counter not work? (screenshot included for explanation / easy code) 1 Answer
I'm trying to make the collision work. But... 2 Answers
Automatic Switching of two or more booleans in Inspector 1 Answer
Is there a way to "Dubug.Log" which gameobject called a certain function? 3 Answers
Reading a var from variable parents 1 Answer