hey, so im having this weird error: Maybe you know how to fix it? Object reference not set to an instance of an object. Here’s the script:
Fixed it.
using UnityEngine;
using System.Collections;
public class AcidZombieControlls : MonoBehaviour {
public float X;
public float speed;
public bool paperStyle;
public bool scaleStyle;
private Transform myTransform;
public float moveSpeed;
public Transform target;
public Transform SpitAreaStart;
public Transform SpitAreaEnd;
public bool spotted = false;
Animator anim;
public Transform Acid;
public Transform AcidSpawnPos;
public bool ImFacingLeft;
public float timeBetweenShots = 5.0f;
void Start ()
{
X = transform.localScale.x;
anim = GetComponent ();
InvokeRepeating(“Spit”, 1.0F, 2F);
}
void Spit()
{
if(ImFacingLeft)
{
GameObject acid = Instantiate (Acid, AcidSpawnPos.position, AcidSpawnPos.transform.rotation) as GameObject;
acid.rigidbody2D.AddForce (Vector2.right * -200);
}
if(!ImFacingLeft)
{
GameObject acid = Instantiate (Acid, AcidSpawnPos.position, AcidSpawnPos.transform.rotation) as GameObject;
acid.rigidbody2D.AddForce (Vector2.right * 200);
}
}
void Update ()
{
if(target.position.x < myTransform.position.x)
{
ImFacingLeft = true;
}
if(target.position.x > myTransform.position.x)
{
ImFacingLeft = false;
}
Vector3 oldEulers = myTransform.eulerAngles;
if (target.position.x < myTransform.position.x)
{
myTransform.position -= myTransform.right * moveSpeed * Time.deltaTime;
//We’re checking inside a threshold so the object doesn’t rapidly flip when even with the player.
if (target.position.x < myTransform.position.x-0.02f)
{
if (paperStyle)
{
oldEulers.y = Mathf.LerpAngle(oldEulers.y, 0, 0.25f);
}
else if (scaleStyle)
{
transform.localScale = new Vector3(-1, 1, 1);
}
else
{
oldEulers.y = 0;
}
}
}// player is left of enemy, move left
if (target.position.x > myTransform.position.x)
{
//If we’re using either rotate style, transform.right will be relative.
if (scaleStyle !paperStyle)
{
myTransform.position += myTransform.right * moveSpeed * Time.deltaTime;
}
else
{
myTransform.position -= myTransform.right * moveSpeed * Time.deltaTime;
}
//We’re checking inside a threshold so the object doesn’t rapidly flip when even with the player.
if (target.position.x > myTransform.position.x + 0.02f)
{
if (paperStyle)
{
oldEulers.y = Mathf.LerpAngle(oldEulers.y, 180, 0.25f);
}
else if (scaleStyle)
{
transform.localScale = new Vector3(1, 1, 1);
}
else
{
oldEulers.y = 180;
}
}
}// player is right of enemy, move right
transform.eulerAngles = oldEulers;
Raycasting();
Behaiviours();
}
void Raycasting()
{
Debug.DrawLine (SpitAreaStart.position, SpitAreaEnd.position, Color.green);
spotted = Physics2D.Linecast (SpitAreaStart.position, SpitAreaEnd.position, 1 << LayerMask.NameToLayer (“Player”));
if(spotted == true)
{
anim.SetBool (“Acid”, true);
speed = 0;
}
if(!spotted)
{
anim.SetBool (“Acid”, false);
speed = 0.1f;
}
}
void Behaiviours()
{
}
void Awake ()
{
myTransform = transform;
}
void FixedUpdate ()
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}
Thanks! :-D:face_with_spiral_eyes: