Answer the question
In order to leave comments, you need to log in
How to switch between characters in unity?
It is necessary that when the button is pressed, the characters switch between themselves. But I had a bug, character 2 does not appear in the place of character 1, but in its original place.
Here is the switch code that is attached to Players, and char1 and char2 are children:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Switzer : MonoBehavior
{
public GameObject char1, char2;
int charOn = 1;
void Start()
{
char1.gameObject.SetActive(true);
char2.gameObject.SetActive(false);
}
public void SwitchCharecter()
{
switch(charOn)
{
case 1:
charOn = 2;
char1.gameObject.SetActive(false);
char2.gameObject.SetActive(true);
break;
case 2:
charOn = 1;
char1.gameObject.SetActive(true);
char2.gameObject.SetActive(false);
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
It seems to me that this is not a bug
Read the parameters of the hidden object and set them for the displayed one
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question