Question by
dimitri0044 · Feb 24, 2019 at 03:17 PM ·
disable object
I want to disable a specific script of the children I don't want to disable the whole object
using System.Collections; using System.Collections.Generic; using UnityEngine; using System;
public class disableComponents : MonoBehaviour {
public int selectedCharacter = 0;
// Use this for initialization
void Start () {
selectCharacter();
}
// Update is called once per frame
void Update () {
int previousSelectedCharacter = selectedCharacter;
if(Input.GetAxis("Mouse ScrollWheel") > 0f)
{
if (selectedCharacter >= transform.childCount - 1)
selectedCharacter = 0;
else
selectedCharacter++;
}
if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
Debug.Log("--");
if (selectedCharacter <= 0)
selectedCharacter = transform.childCount-1;
else
selectedCharacter--;
}
if(previousSelectedCharacter != selectedCharacter)
{
selectCharacter();
}
}
void selectCharacter()
{
int i = 0;
foreach(Transform character in transform)
{
if (i == selectedCharacter)
character.gameObject.SetActive(true);
else
character.gameObject.SetActive(false);
i++;
}
}
}
Comment
Best Answer
Answer by ChristosKapenis · Feb 24, 2019 at 03:25 PM
Use character.gameObject.GetComponent<ScriptName>().enabled = false;
you where wright but I needed to add parentheses after
Sorry, my bad. I was typing fast and forgot to include the parentheses but I'm glad I helped.
Answer by dimitri0044 · Feb 24, 2019 at 03:39 PM
if I replace character.gameObject.SetActive(false); with what you said and the one whit true it gives an error
it says it is a method and it isn't valid in the context @Christos$$anonymous$$apenis
Your answer