Well for an assignment I was to fix a few scripts on my own. I managed to fix one fully by myself and another to only having a few errors which kind people on here helped me fix. Now Ive managed to get this final script down to the last few errors. (Going from 22 to 5 and being stuck) IF anyone is willing to assist me in fixing the errors and telling me what was wrong with them and how to fix it I would really be grateful. I’m very new to the scripting scene but I want to learn all I can!
public var health : int = 5; // number of hits before game over
public var moveSpeed : int = 3; // horizontal speed
public var jumpSpeed : float = 8; // jumping speed
public var turnSpeed : float = 2; // turning rate
private var controller : CharacterController; // reference to CharacterController component
private var velocity : Vector; // current speed
function Start ()
{
}
function Update ()
{
// assume no input
velocity.x = 0;
velocity.z = 0;
// forward
if (Input.GetKey("w") || Input.GetKey("up"))
{
velocity + transform.forward * moveSpeed;
}
// back
else if(Input.GetKey("s") || Input.GetKey("down"))
{
velocity + transform.back * moveSpeed;
}
// turn left
if(Input.GetKey("a") || Input.GetKey("left"))
{
transform.rotate(0, -turnSpeed, 0);
}
// turn right
else if(Input.GetKey("d") || ("right"))
{
Transform.Rotate(0, turnspeed, 0);
}
if(isGrounded)
{
// jump
if(Input.GetKeyDown("space"))
{
velocity += transform.up * jumpSpeed;
}
else
{
velocity.y = 0;
}
}
// gravity
velocity += Physics.gravity * Time.deltaTime;
// apply motion
controller.Move(velocity * Time.deltaTime);
function onTriggerEnter()
{
// detection radius
if(trigger.name == "Enemy")
{
// set enemy to alert
// Enemy is the name of the enemy script
// alert is a variable on the Enemy script
trigger.GetComponent(Enemy).alert = true;
}
// getting hit
else if(trigger.name == "Body")
{
health--;
if(health <= 0)
{
transform.DetachChildren();
Destroy(gameObject);
}
}
}
function OnTriggerEnter(trigger : collider)
{
// leaving detection radius
if(trigger.name == "Enemy")
{
trigger.GetComponent(Enemy).alert = false;
}
}