I got the code to where the player can push a button to swap characters, but the camera defaults it’s default position upon pushing the button.
here is part of code
camera code is basically smoothfollow 2D
var target1 : Transform;
var target2 : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector2;
function Start()
{
thisTransform = transform;
}
function Update()
{
if (Globalscript.victimstate == 1)
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, target1.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, target1.position.y, velocity.y, smoothTime);
}
if (Globalscript.victimstate == 2)
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, target2.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, target2.position.y, velocity.y, smoothTime);
}
}
and here is code to swap states
if (Input.GetButtonDown("Switch"))
{
Globalscript.victimstate = 2;
print(Globalscript.victimstate);
var spawnplayer = Instantiate(nextCharacter, transform.position, transform.rotation);
Destroy(gameObject);
}
The state does changes but the camera isn’t following new character.The character does change.