Character swap breaks movement.
I have a simple activate/deactivate function for the six playable models, when the game loads the characters swap but unless the chosen character is already active before the game launches (or if any other are active before launch) the move object function in the motor script fails.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class charicterSelecter : MonoBehaviour {
private void Awake()
{
if (PlayerPrefs.GetInt("Charicter") == 0)
{
Werewolf.SetActive(false);
Zombie.SetActive(true);
Pirate.SetActive(false);
Knight.SetActive(false);
Ninja.SetActive(false);
Vampire.SetActive(false);
PlayerPrefs.SetInt("Check1", 1);
}
if (PlayerPrefs.GetInt("Charicter") == 1)
{
Werewolf.SetActive(false);
Zombie.SetActive(false);
Pirate.SetActive(false);
Knight.SetActive(true);
Ninja.SetActive(false);
Vampire.SetActive(false);
PlayerPrefs.SetInt("Check1", 1);
}
}
// Use this for initialization
void Start () {
PlayerPrefs.SetInt("Charicter", PlayerPrefs.GetInt("Charicter"));
PlayerPrefs.SetInt("Check1", 0);
}
public GameObject Zombie;
public GameObject Pirate;
public GameObject Knight;
public GameObject Ninja;
public GameObject Werewolf;
public GameObject Vampire;
// Update is called once per frame
void Update () {
PlayerPrefs.SetInt("Charicter", PlayerPrefs.GetInt("Charicter"));
}
public void OnZombie() {
PlayerPrefs.SetInt("Charicter",0);
}
}
Answer by Keergen · Feb 17, 2019 at 09:05 PM
Solved,
For those with the same issue:
Place all characters with controllers disabled into an empty game object parent. place all scripts to run the characters into the parent object basically making an invisible player. then you can use the above set-active functions to swap the model... ugh one of those "if it was a snake it woulda bit ya" moments.
Your answer
Follow this Question
Related Questions
Character flies up and gets stuck there, won't move forward? 1 Answer
Jumping with slight air control while retaining velocity 1 Answer
Character's jumping mechanism stuck into something invisible 1 Answer
Issues with making a climbing script compatible with CharacterController 0 Answers
Adding a CharacterController makes my player move around the map involuntarily 0 Answers