Writing to call a method in a component in another object

To call a method in a component in another object

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class peng : MonoBehaviour
{
    
    
   void OnTriggerEnter2D(Collider2D collision)
    {
    
    
        if(collision.tag=="tou")
        {
    
    
            GameObject.Find("Gamemangen").GetComponent<Gamemange>().GameOver();
        }
    }
   
}

Guess you like

Origin blog.csdn.net/qq_46289420/article/details/109299309