Question by
rob444 · Jun 14, 2016 at 04:15 PM ·
animationpositioningswitch characters
Switch player model, positon, camera and animate
Ok so i'm making a transformers game. I have two game objects of the same model. one is in robot form the second in car form.
My goal is: on button press play animation, switch models, move one model and switch and new model appears in same place and switch cameras.
What I've managed is switching models and cameras but can't get the animations to play and the models wont swap in place.
Lots of googeling and trail and error and having no luck. Any help would be great thanks.
in C#
using UnityEngine;
using System.Collections;
public class Change : MonoBehaviour {
public GameObject Player;
public GameObject Car;
public GameObject OptimusPrimePlayer;
public GameObject OptimusPrimeCar;
private int modelNumber;
Vector3 carPos;
Vector3 playerPos;
//public GameObject CameraCar;
//public GameObject CameraPlayer;
// Use this for initialization
void Start () {
modelNumber = 1;
Car.SetActive(false);
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire3"))
{
ModelSwitch();
}
/* if (Input.GetButtonDown("Fire3"))
{
if (CameraPlayer.GetComponent<Camera>().enabled)
{
CameraCar.GetComponent<Camera>().enabled = true;
CameraPlayer.GetComponent<Camera>().enabled = false;
}
else if (CameraCar.GetComponent<Camera>().enabled)
{
CameraPlayer.GetComponent<Camera>().enabled = true;
CameraCar.GetComponent<Camera>().enabled = false;
}
}*/
}
void ModelSwitch()
{
if (modelNumber == 1)
{
playerPos = Player.transform.position;
Debug.Log(playerPos);
//OptimusPrimeCar.GetComponent<Animation>().Play("Player to car");
Player.SetActive(false);
Car.SetActive(true);
carPos = playerPos;
Debug.Log(carPos);
modelNumber = 2;
}
else if (modelNumber == 2)
{
carPos = Car.transform.position;
Debug.Log(carPos);
//OptimusPrimeCar.GetComponent<Animation>().Play("car to player");
Car.SetActive(false);
Player.SetActive(true);
playerPos = carPos;
Debug.Log(playerPos);
modelNumber = 1;
}
}
}
Comment
got the position thing going just cant get the animations to play now
Your answer
![](https://koobas.hobune.stream/wayback/20220612082928im_/https://answers.unity.com/themes/thub/images/avi.jpg)