So im really new to C# and Unity ive been using it for some days now , and ive been following a tutorial and have reached a point where an error appears and i just can’t fix it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CreateEnemyBtn : MonoBehaviour
{
[SerializeField]
private GameObject targetEnemyUnitPrefab;
//where in interface the button will appear
[SerializeField]
private Vector2 initialPosition, itemDimensions;
[SerializeField]
private KillEnemy killEnemyScript;
void Awake()
{
// Find the units menu.
GameObject enemyUnitsMenu = GameObject.Find(“EnemyUnitsMenu”);
//Calculate the item position
GameObject[ ] existingItems = GameObject.FindGameObjectsWithTag(“TargetEnemyUnit”);
Vector2 nextPosition = new Vector2(
initialPosition.x + (Mathf.Pow(-1,existingItems.Length)*50 + 50),
initialPosition.y -50 * existingItems.Length + 50
);
//instantiate the item
GameObject targetEnemyUnit = Instantiate(targetEnemyUnitPrefab, enemyUnitsMenu.transform);
targetEnemyUnit.name = “Target” + gameObject.name;
targetEnemyUnit.transform.localPosition = nextPosition;
targetEnemyUnit.transform.localScale = new Vector2(1, 1);
targetEnemyUnit.GetComponent().onClick.AddListener (() => SelectEnemyTarget());
killEnemyScript.menuItem = targetEnemyUnit;
}
public void SelectEnemyTarget()
{
}
The error that appears is
Assets\TheGame\CombatStuff\Combat Characters\EnemyParty\Slime\CreateEnemyBtn.cs(39,48): error CS1061: ‘Button’ does not contain a definition for ‘onClick’ and no accessible extension method ‘onClick’ accepting a first argument of type ‘Button’ could be found (are you missing a using directive or an assembly reference?)
Thanks in advance !