How to get an instance of an object to reference an instance of a different object?
In my game I make instances of 2 seperate objects and when the player spawns one, the other one also spawns. The player can spawn multiple instances of the same object so I need to track and link the 2 seperate objects and only the objects that spawn together. I've given both of the objects unique ids when they spawn in but I don't know where to go from here. I want to be able to reference variables and sprite renderers and things like that.
Object One's script:
using System;
using UnityEngine;
public class FishTab_MB : MonoBehaviour
{
public Guid UniqueId { get; }
public FishTab_MB()
{
UniqueId = Guid.NewGuid();
}
private void Start()
{
print("FishTab_MB UniqueId: " + UniqueId);
}
}
Object two's script:
using System;
using System.Collections;
using Unity.VisualScripting;
using UnityEngine;
public class FishAI_MB : MonoBehaviour
{
SpriteRenderer fishSr;
public Guid UniqueId { get; }
void Start()
{
print("FishAI_MB UniqueId: " + UniqueId);
}
public FishAI_MB()
{
UniqueId = Guid.NewGuid();
}
}