';' expected. Add semicolon at the end.
Where is a semicolon needed in this code?
if(currenthealth <= 0) {
dead=true;
}
if(dead) {
AI=(AI)Component.GetComponent("AI");
}
if(ai) {
ai.dead=true;
currenthealth = 0;
}
Answer by Unity_scat · May 19, 2016 at 10:24 PM
I don't see the problem. Usually it would be enclosing of functions if it wasn't a semicolon.
Okay then let me give you my whole script. var DamageAmount : int = 5; var TargetDistance : float; var AllowedRange : float = 15; var currenthealth : int = 100; function Update () { if(Input.GetButton("Fire1")) {
var Shot : RaycastHit;
if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Shot)) {
TargetDistance = Shot.distance;
if(TargetDistance < AllowedRange) {
Shot.transform.Send$$anonymous$$essage("LoseHealth", 2);
}
}
if(currenthealth <= 0) {
dead=true;
}
if(dead) {
ai=(ai) Component.GetComponent("AI");
}
if(ai) {
ai.dead=true;
currenthealth = 0;
}
}
}
Answer by Landern · May 19, 2016 at 10:53 PM
ai is not a recognized type. If you're trying to type cast and your script name is "AI", then you should use the same case for casting.
You should also define AI for clarity, if AI is a type you can use the generic GetComponent for UnityScript so you don't have to worry about type casting.
var DamageAmount : int = 5;
var TargetDistance : float;
var AllowedRange : float = 15;
var currenthealth : int = 100;
function Update ()
{
if(Input.GetButton("Fire1"))
{
var Shot : RaycastHit;
var ai : AI;
if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Shot))
{
TargetDistance = Shot.distance;
if(TargetDistance < AllowedRange) {
Shot.transform.SendMessage("LoseHealth", 2);
}
}
if(currenthealth <= 0)
{
dead=true;
}
if(dead)
{
ai= GetComponent.<AI>();
}
if(ai)
{
ai.dead=true;
currenthealth = 0;
}
}
}
What im trying to do is get the dead code from another script to run when currenthealth <= 0
Your answer
Follow this Question
Related Questions
Can I use ZeroC Ice with Unity? 0 Answers
How to stop model form rotating back to face down? 1 Answer
Enemy keeps floating throw roof? 0 Answers
Spawn a dot for every number typed? 0 Answers
enemy looking randomly? 0 Answers