Hey there, I followed the 2D Character Controller tutorial, and created a 2D Character. I am trying to achieve an effect, where you press a button, and it switches to another character in the scene, and you can then control the second character, while the first one is standing still. I can achieve this effect, but I am having some different problems, first is, that the first character, is still doing the running animation when I am switching, I already got the camera working so that it switches. Any help is appreciated, and it is in C#
Here is my code for the Player Controller:
using UnityEngine;
using System.Collections;
public class PlayerControllerScript1 : MonoBehaviour {
public GameObject camera;
public float jumpForce;
public float maxSpeed;
bool facingRight = true;
Animator anim;
//on ground and so on
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
void Start () {
anim = GetComponent<Animator>();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool("Ground", grounded);
anim.SetFloat("vSpeed", rigidbody2D.velocity.y);
//Walking Animation and Movement
float move = Input.GetAxis ("Horizontal");
anim.SetFloat("Speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
//Flipping the Character
if(move > 0 && !facingRight)
Flip ();
else if(move < 0 && facingRight)
Flip ();
}
void Update(){
if(grounded && Input.GetKeyDown(KeyCode.Space)){
anim.SetBool("Ground", false);
rigidbody2D.AddForce(new Vector2(0, jumpForce));
}
}
void Flip(){
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}