I have an attack script for my enemies, I wanted to make the range of the raycast editable in the inspector, but for some reason, it’s not showing up in the inspector.
Here’s my script,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BitingMold : MonoBehaviour
{
public Animator animator;
public GameObject attackTrigger;
public EnemyMover mover;
public EnemyCreator enemy;
public bool isAttacking;
private float speed, baseSpeed;
public float rayRange = 0;
public LayerMask playerLayer;
public Player player;
private void Start()
{
enemy = this.GetComponent<EnemyCreator>();
player = FindObjectOfType<Player>();
attackTrigger = GameObject.Find("EnemyAttackTrigger");
attackTrigger.SetActive(false);
mover = this.GetComponent<EnemyMover>();
baseSpeed = enemy.speed;
animator = this.GetComponent<Animator>();
}
private void Update()
{
RaycastHit2D info = Physics2D.Raycast(transform.position, mover.isRight ? Vector2.right : Vector2.left, rayRange, playerLayer);
if (info.collider != null)
{
if(!this.GetComponentInParent<EnemyCreator>().isDead && !isAttacking && !player.isDead)
{
StartCoroutine(Attack());
}
}
}
IEnumerator Attack()
{
if (!this.GetComponentInParent<EnemyCreator>().isDead)
{
enemy.speed = 0.1f;
isAttacking = true;
animator.SetBool("isAttacking", true);
yield return new WaitForSeconds(0.5f);
attackTrigger.SetActive(true);
yield return new WaitForSeconds(0.25f);
animator.SetBool("isAttacking", false);
if (attackTrigger != null)
{
attackTrigger.SetActive(false);
}
isAttacking = false;
enemy.speed = baseSpeed;
}
}
}
All the other public variables are showing up, but the rayRange is not showing up, even if I put [SerializeField]. Can anyone tell what I’m doing wrong? Haha.
Thanks in advance.