Hello Friends,
I am stuck with this error for the past 2 days and have gone through my code over and over again but unable to figure out what’s missing. Appreciate any help on what’s going wrong with my script - this is to move my player through a scene. Thanks much.
using UnityEngine;
using System.Collections;
public class MouseController : MonoBehaviour
{
public float jetpackForce = 75.0f; // force applied to the mouse when the jetpack is on
private Rigidbody2D rb;
public float forwardMovementSpeed = 3.0f; //force applied to the mouse in X axis
public Transform groundCheckTransform;
private bool grounded; // checking if the player is grounded
public LayerMask groundCheckLayerMask; // contain list of all ground items
Animator animator;
public ParticleSystem jetpack; // turn jetpack on/off
private bool dead = false;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
}
void FixedUpdate()
{
bool jetpackActive = Input.GetButton("Fire1"); //detect left button click
if (jetpackActive)
{
rb.AddForce(new Vector2(0,jetpackForce));
}
If (!dead) **// - this is where I am getting the error prompt " ; expected"**
{
Vector2 newVelocity = GetComponent<Rigidbody2D>().velocity;
newVelocity.x = forwardMovementSpeed;
GetComponent<Rigidbody2D>().velocity = newVelocity;
}
UpdateGroundedStatus();
AdjustJetPack(jetpackActive);
}
void UpdateGroundedStatus() //adjust player animation whether it's grounded or flying
{
//1
grounded = Physics2D.OverlapCircle(groundCheckTransform.position, 0.1f, groundCheckLayerMask);
//2
animator.SetBool("grounded", grounded);
}
void AdjustJetPack(bool jetpackActive)
{
jetpack.enableEmission = !grounded;
//jetpack.emission.enabled = !grounded;
jetpack.emissionRate = jetpackActive ? 300.0f : 75.0f;
//jetpack.emission.rate = jetpackActive ? 300.0f : 75.0f;
}
void OnTriggerEnter2D(Collider2D collider)
{
HitByLaser (collider);
}
void HitByLaser(Collider2D laserCollider)
{
dead = true;
}
}