Hello,
Im trying to access a panel with the name Interface that is child of canvas,
Inside Interface I have button upgrade.
Of course I assigned the function inside interface to the button.
The code should do the following:
After I click the turret … it call to a function inside Interface that aim to set the last turret Clicked.
And while I click the Upgrade button it should set the new properties inside the script of TurretSet.
- Trying using GameObject Instead of transform.
- Maybe I’m not accessing the canvas currectly?
Interface Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Interface : MonoBehaviour
{
public Transform _turretSet;
public void SetTurret(Transform turretSet)
{
_turretSet = turretSet;
}
public void UpgradeTarget()
{
Turret turretSetComp = _turretSet.GetComponent<Turret>();
turretSetComp.Damage += 100;
}
}
The script Inside turret
void OnMouseDown ()
{
GameObject interfacePanel = GameObject.Find("Canvas/Interface");
Interface interfaceScript = interfacePanel.GetComponent<Interface>();
interfaceScript.SetTurret(transform);
}