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, 2012 at 11:25 PM

PerfectOrigin gravatar image

PerfectOrigin
3 12 9 9

(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, 2012 at 11:28 PM

DaveA gravatar image

DaveA
33.1k 416 334 442

(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:

x8959
x687
x306

asked: Feb 13, 2012 at 11:25 PM

Seen: 1382 times

Last Updated: Feb 13, 2012 at 11:28 PM