- Home /
Question by
PerfectOrigin · Feb 13, 2012 at 11:25 PM ·
c#programminggetcomponent
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;
}
}
}
Comment
Answer by DaveA · Feb 13, 2012 at 11:28 PM
var playerHealth = playerHealth
That's JS, and would need a semicolon at the end anyway