How can I call the a function from another script?

Hi!. I’m a new programmer and I need to call the LoadContent from the ContentController script in the AddModel script. Could someone please help me?

Content Controller

using System;
using UnityEngine;

public class ContentController : MonoBehaviour
{
    public API api;
    public void LoadContent(string name) {
        DestroyAllChildren();
        api.GetBundleObject(name, OnContentLoaded, transform);
    }

    public void OnContentLoaded(GameObject content) {
        //do something cool here
        Debug.Log("Loaded: " + content.name);
    }

    void DestroyAllChildren() {
        foreach (Transform child in transform) {
            Destroy(child.gameObject);
        }
    }

}

AddModel

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class AddModel : MonoBehaviour
{
    public ARRaycastManager raycastManager;
    public GraphicRaycaster raycaster;

    void Update() {

        if (Input.GetMouseButtonDown(0) && !IsClickOverUI()) {
        
            List<ARRaycastHit> hitPoints = new List<ARRaycastHit>();
            raycastManager.Raycast(Input.mousePosition, hitPoints, TrackableType.Planes);

            if (hitPoints.Count > 0) {
                Pose pose = hitPoints[0].pose;
                transform.rotation = pose.rotation;
                transform.position = pose.position;
            }
        }
    }

    bool IsClickOverUI() {
        //dont place content if pointer is over ui element
        PointerEventData data = new PointerEventData(EventSystem.current) {
            position = Input.mousePosition
        };
        List<RaycastResult> results = new List<RaycastResult>();
        raycaster.Raycast(data, results);
        return results.Count > 0;
    }

   

}

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms