Hi,
I’ve written a script that switches my character from her normal state to her Ball form. They are completely different game objects with different physics and movement controls. Otherwise, I would have used renderer.enabled. I was able to get the two objects two switch by making them children of a parent object (which I’ve called “MainCharacter” in the script) and attaching the following script to the parent. The problem is that once an object becomes active, it starts at the place it was last active instead of the place where the object before it was active, and it retains its last active velocity properties. So what I’d like is when the switch happens, the newly active object inherits the velocity and transform of the previously active object. Hope that all makes sense! Here is the code in c#
using UnityEngine;
using System.Collections;
public class SwitchStates : MonoBehaviour {
public Transform MainCharacter;
public GameObject MC;
public GameObject Ball;
public bool ball;
public bool normal;
void Start()
{
Ball.SetActive (false);
MC.SetActive(true);
}
void Update ()
{
if (MC.activeSelf)
normal = true;
else
normal = false;
if (Ball.activeSelf)
ball = true;
else
ball = false;
if (Input.GetButtonDown ("Fire2") && normal)
{
Ball.transform.position = MainCharacter.position;
MC.SetActive(false);
Ball.SetActive(true);
}
if (Input.GetButtonDown ("Fire2") && ball)
{
MC.transform.position = MainCharacter.position;
Ball.SetActive(false);
MC.SetActive(true);
}
}
}
thanks!!