I have a pickup script. I have a script on objects that will get picked up. I want the object’s script to call a function where the players pickup are stored. So basically I need a script to call another’s script function. This is in C# but if you tell me how to do it in javascript I can figure out how to do it in C# without help.
I want the function changer to be called
using UnityEngine;
using System.Collections;
public class objectStorage : MonoBehaviour {
public int sphere = 0;
public static void Changer(int amount)
{
//change the amount of spheres
sphere+=amount;
}
}
and it will be called fromt his script
using UnityEngine;
using System.Collections;
public class pickupObject : MonoBehaviour{
public GameObject controller;
public bool debug = false;
public bool debug1 = false;
void OnTriggerStay(Collider collision)
{
if(collider.gameObject.tag == "Pickup")
{
debug = true;
if(Input.GetButtonDown("Pickup"))
{
print ("Destroyed the object");
controller.GetComponent<objectStorage>().Changer(1);
Destroy(collider.gameObject);
}
}
}
}