- Home /
Question by
TheShadyColombian · Aug 30, 2014 at 07:57 PM ·
prefabinspector
Enemy prefab's script won't keep inspector-applied settings.
i need the highlighted part to be set as the player, preferably using "void start", what would i need to put inside?
using UnityEngine;
using System.Collections;
public class ExperimentalEnemy : MonoBehaviour {
public Transform target;
public int moveSpeed;
public float rotationSpeed;
public float noChaseRange = 31.5f;
public int HitBoxRadius;
public ExperimentalDeath Damage;
public float Health = 10f;
private Transform myTransform;
public GameObject Char;
public Animator EnemyAnim;
public GameObject PoofEmmiter;
public bool isDead;
void Awake() {
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.Find("MonstercatChar");
target = go.transform;
isDead = false;
GameObject Char = GameObject.Find("MonstercatChar");
ExperimentalDeath Damage = Char.GetComponent<ExperimentalDeath>();
HitBoxRadius = 35;
}
// Update is called once per frame
void Update () {
if (Health < 0.1) {
isDead = true;
EnemyDie ();
}
Debug.DrawLine(target.position, myTransform.position, Color.blue);
if (isDead == true){
Health = 0F;
Destroy (collider);
if(Random.Range(0f, 20f)< 1){
Instantiate (PoofEmmiter, transform.position, transform.rotation);
}
}
if (isDead != true){
//Look at target
transform.LookAt(target.position);
if(Vector3.Distance(target.position, myTransform.position) > noChaseRange) {
//Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
if(Vector3.Distance(target.position, myTransform.position) < HitBoxRadius) {
Damage.DamageChar(Random.Range(0.01F, 0.2F));
Debug.Log ("Is Damaging " + Char);
}
}
}
public void EnemyDamage (float amount) {
Health -= amount;
}
public void EnemyDie () {
//if(Random.Range(0f, 10f)< 1){
//}
Destroy (gameObject, 2F);
EnemyAnim.SetBool ("Die", true);
}
void OnTriggerEnter (Collider other){
if (other.gameObject == GameObject.FindGameObjectWithTag ("Bullet")){
EnemyDamage(Random.Range(0.1F, 0.2F));
Destroy (other);
}
}
}
screen shot 2014-08-30 at 3.48.29 pm.png
(56.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Set variable in prefab to not set to prefab 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to set a default prefab on a C# script? 1 Answer
Is an object created when dragging a prefab to a GameObject script field 1 Answer
Assign object in hierarchy as public variable in prefab 1 Answer