using UnityEngine;
using System.Collections;
public class CharacterController : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = .1f;
public LayerMask whatIsGround;
public float jumpForce = 450f;
void Start ()
{
anim = GetComponent<Animator>();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
anim.SetFloat ("vSpeed", GetComponent<Rigidbody2D> ().velocity.y);
if (!grounded)
return;
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
GetComponent<Rigidbody2D> ().velocity = new Vector2 (move * maxSpeed, GetComponent<Rigidbody2D> ().velocity.y);
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Update()
{
if(grounded && Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool ("Ground", false);
GetComponent<Rigidbody2D>().AddForce(new Vector2 (0, jumpForce));
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
is my player controller script. and the following is my shooter script where i get the error:
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public Rigidbody2D Bullet;
public float speed = 20f;
public Transform ShotSpawn;
public float fireRate;
private float nextFire;
public CharacterController PlayerControl;
// Use this for initialization
void Awake()
{
PlayerControl = transform.root.GetComponent<CharacterController> ();
}
void Update () {
if (Input.GetButton ("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
if (PlayerControl.facingRight) {
Rigidbody2D bulletInstance = Instantiate (Bullet, transform.position, Quaternion.Euler (new Vector3 (0, 0, 0))) as Rigidbody2D;
bulletInstance.velocity = new Vector2 (speed, 0);
}
else {
Rigidbody2D bulletInstance = Instantiate (Bullet, transform.position, Quaternion.Euler (new Vector3 (0, 0, 180f))) as Rigidbody2D;
bulletInstance.velocity = new Vector2 (-speed, 0);
}
}
}
}