x


GetComponent C#

How can I fix this script, I am getting this error, "error CS1525: Unexpected symbol 'playerHealth' "

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;


public class SmartAi : MonoBehaviour 
{
    public Transform target;
    public Transform projectile;
    public Transform myTransform;
    public GameObject player;
    int moveSpeed = 5;
    bool attacking = true; 
    int ammo = 100;
    int close = 5;



    // Use this for initialization
    void Start () 
    {

    }

    // Update is called once per frame
    void Update () 
    {
       transform.LookAt(target);
       move();
       healthPoints();
       if(attacking == true)
       {
         //if(Vector3.Distance(transform.position, target.position) < close)
         //{
          shoot();
         //}
       }

    }

    void shoot ()
    {
       var playerHealth = playerHealth
       playerHealth = target.GetComponent("playerHealth");
       playerHealth.health = playerHealth.health - 10; 

    }
    void move ()
    {
       myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
    }
    void healthPoints ()
    {
       int hitPoints = 100;
       if(hitPoints <= 0)
       {
         Destroy(gameObject);
       }
       if(hitPoints >= 100)
       {
         hitPoints = 100;
       }
    }
}
more ▼

asked Feb 13 '12 at 11:25 PM

PerfectOrigin gravatar image

PerfectOrigin
3 4 5 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

var playerHealth = playerHealth

That's JS, and would need a semicolon at the end anyway

more ▼

answered Feb 13 '12 at 11:28 PM

DaveA gravatar image

DaveA
32.4k 158 176 278

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7641
x611
x264

asked: Feb 13 '12 at 11:25 PM

Seen: 1214 times

Last Updated: Feb 13 '12 at 11:28 PM