Hi i am trying to acces function in other script on other object but i am getting this error: Assets/selecting.js(12,32): BCE0019: ‘ToggleSelection’ is not a member of ‘UnityEngine.Component’. When trying to call a function ToggleSelection. What am i doing wrong?
First script:
#pragma strict
var hitInfo : RaycastHit;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hitInfo, Mathf.Infinity) && hitInfo.transform.gameObject.tag == "Unit")
{
var script = hitInfo.transform.gameObject.GetComponent("ToggleSelected");
script.ToggleSelection();
}
}
}
Second script:
#pragma strict
public var selected : System.Boolean = false;
public function ToggleSelection()
{
if(selected == false)
{
selected=true;
}
else
{
selected=false;
}
}