Chapter 6 OnTrigger Problem

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ArenaWall : MonoBehaviour {
private Animator arenaAnimator;

// Use this for initialization
void Start () {
    GameObject arena = transform.parent.gameObject;
    arenaAnimator = arena.GetComponent<Animator>();

    void OnTriggerEnter(Collider other) {
        arenaAnimator.SetBool("IsLowered", true);
    }
    void OnTriggerExit(Collider other) {
        arenaAnimator.SetBool("IsLowered", false);
    }

}

// Update is called once per frame
void Update () {
	
}

}

Hi, I am trying to create the ArenaWall script, but for some reason the OnTriggerEnter and OnTriggerExit create errors saying that both variables are declared bu never used. How would I solve this?
Thank you.

Hi @vsummer7

I believe you have to move those functions outside of the โ€˜Startโ€™ function. So it should look like this:

void Start () {
      GameObject arena = transform.parent.gameObject;
      arenaAnimator = arena.GetComponent<Animator>();
}

void OnTriggerEnter(Collider other) {
     arenaAnimator.SetBool("IsLowered", true);
}
void OnTriggerExit(Collider other) {
     arenaAnimator.SetBool("IsLowered", false);
}

It works, Thank you for your help.

This topic was automatically closed after 166 days. New replies are no longer allowed.