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();
    }
}
reddit.com

How to apply momentum?

I want to apply momentum after you let go so in if (!hold.IsPressed()) How would I do that?

Code:

using System.Collections;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class Food_MB : MonoBehaviour
{

    public bool isTouchingMouse = false;
    public bool isheld = false;

    public float defaultFoodSpeed = 1f;
    public float gravity = 1f;
    private float foodSpeed = 1f;
    private float noGravity = 0f;

    private PlayerInput playerInput;

    private InputAction hold;

    private Vector2 mousePos;

    private Rigidbody2D foodRb;

    void Start()
    {
        playerInput = GetComponent<PlayerInput>();
        if (playerInput != null)
        {
            hold = playerInput.currentActionMap.FindAction("Hold");
        }
        foodSpeed = defaultFoodSpeed;
        foodRb = GetComponent<Rigidbody2D>();
        foodRb.gravityScale = gravity;
    }

    private void Update()
    {

        // Get the mouse position from the New Input System

        mousePos = Mouse.current.position.ReadValue();

        // Convert the screen position to world position

        Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, 0));

        // Check if the mouse is touching this GameObject's collider and if the hold action is being performed

        Collider2D hit = Physics2D.OverlapPoint(worldPos);

        if (hit != null && hit.gameObject == this.gameObject && hold != null && hold.IsPressed())
        {
            //Debug.Log("Hold action is being performed");
            foodRb.gravityScale = noGravity;
            isheld = true;
            foodSpeed = defaultFoodSpeed;
            transform.position = Vector2.MoveTowards(transform.position, worldPos, foodSpeed * Time.deltaTime);
        }
        else if(hold.IsPressed() && (hit == null || !hit.gameObject == this.gameObject) && isheld == true)
        {
            //Debug.Log("Mouse is not touching the object but object is held");
            foodSpeed = foodSpeed + 1f;
            transform.position = Vector2.MoveTowards(transform.position, worldPos, foodSpeed * Time.deltaTime);

        }
        if (!hold.IsPressed())
        {
            //Debug.Log("Object dropped!");
            foodRb.gravityScale = gravity;
            foodSpeed = defaultFoodSpeed;
            isheld = false;
        }
    }
}
reddit.com
u/Silent_Reputation596 — 3 days ago

How to make an object follow the mouse?

I'm trying to get the object this script is on to follow the mouse when you click on the object. I've managed to make detect when you are holding down the object but I can't get the object to move. Pls help!

using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class Food_MB : MonoBehaviour
{

    public bool isTouchingMouse = false;
    public bool isheld = false;

    private PlayerInput playerInput;

    private InputAction hold;

    private Vector2 mousePos;

    void Start()
    {
        playerInput = GetComponent<PlayerInput>();
        if (playerInput != null)
        {
            hold = playerInput.currentActionMap.FindAction("Hold");
        }
    }

    private void Update()
    {

        // Get the mouse position from the New Input System

        mousePos = Mouse.current.position.ReadValue();

        // Convert the screen position to world position

        Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, 0));

        // Check if the mouse is touching this GameObject's collider

        Collider2D hit = Physics2D.OverlapPoint(worldPos);

        if (hit != null && hit.gameObject == this.gameObject)
        {
            //Debug.Log("Mouse is touching " + this.gameObject.name);
            isTouchingMouse = true;
        }
        else 
        {
            isTouchingMouse = false;
        }

        if (hold != null && hold.IsPressed())
        {
            Debug.Log("Hold action is being performed");
            Vector2.MoveTowards(transform.position, mousePos, 1f * Time.deltaTime);
        }
        else
        { 
            Debug.Log("Hold action is not being performed");
        }

    }
}
reddit.com
u/Silent_Reputation596 — 4 days ago

If people manage to move their pokemon from the 3ds to the switch after bank shutdown would that pokemon be ineligible for the hall of fame?

I know that the rules say no hacking but then how old pokemon become ribbon masters? Would their be a separate category for mons who are stuck in the 3ds games?

reddit.com
u/Silent_Reputation596 — 5 days ago

How to flip the sprite instead of going upside down?

This is my code, I want to have the sprite flip when it rotates to far down instead of rotating upside down like it does in the video. Any ideas?

using System.Collections;
using Unity.VisualScripting;
using UnityEngine;

public class FishAI_MB : MonoBehaviour
{

    FishAIController_MB fishAIController;

    public int currentTarget;

    public int swimDecision;

    void Start()
    {
        fishAIController = Object.FindFirstObjectByType<FishAIController_MB>();
        if (fishAIController == null)
        {
            Debug.Log("Fish is Null");
        } 
        StartCoroutine(StartSwimDecicion());
    }

    IEnumerator StartSwimDecicion()
    {
        Debug.Log("Start Swim Decision");
        swimDecision = Random.Range(0, 2);

        if (swimDecision == 0)
        {
            StartCoroutine(SwimToTarget());
        }
        else if (swimDecision == 1)
        {
            StartCoroutine(Wait());

        }
        yield return null;
    }

    IEnumerator SwimToTarget()
    {
        Debug.Log("Swim to Target");
        currentTarget = Random.Range(0, fishAIController.targets.Length);
        while (Vector2.Distance(transform.position, fishAIController.targets[currentTarget].transform.position) > 0.1f)
        {
            transform.position = Vector2.MoveTowards(transform.position, fishAIController.targets[currentTarget].transform.position, 1f * Time.deltaTime);
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Vector3.forward, fishAIController.targets[currentTarget].transform.position - transform.position), 1f * Time.deltaTime);
            yield return null;
        }
        StartCoroutine(StartSwimDecicion());
        yield return null;
    }

    IEnumerator Wait()
    {
        Debug.Log("Wait");
        yield return new WaitForSeconds(1);
        StartCoroutine(StartSwimDecicion());
    }
}
u/Silent_Reputation596 — 5 days ago

Horizontal Layout Group not updating.

I have 2 text objects that are constrained by a parent with a horizontal layout group. I update one of the text objects on game start but the text object overlaps the other one. How do I get it to update? I've tried to call a layout rebuilder after the text is updated but it doesn't work.

Anyone got any ideas?

u/Silent_Reputation596 — 7 days ago

Black and White Ribbons.

I'm gonna make a shiny purloin a ribbon master because it reminds be of my cat, beans, and I want to immortalise her in Pokemon forever. I know that Black and White has no ribbons to obtain so my question is should I playthrough black and white once I get her just for fun or should I just move on to kalos? I'm looking for both opinions and whether doing this would make ribbon collecting harder.

reddit.com
u/Silent_Reputation596 — 14 days ago
▲ 0 r/Roms

Black and white demake?

Iv been thinking about remaking Pokemon black and white in the gba engine with the fire red graphics. Would anyone be interested in playing something like that?

reddit.com
u/Silent_Reputation596 — 2 months ago

Letter keys not working

My keyboard is plugged in and its rgb so I know that its connected properly but none of the letter keys work. Every other key still works. I left my computer, camp back a couple mins later and the letters are not working No updates happened, nothing was typed on the keyboard. I have restarted my pc, plugged in and out my keyboard but it not working. pls help

reddit.com
u/Silent_Reputation596 — 2 months ago

Auto join based on race?

I want to have a playthrough where I only have ancients and the colonies goal is to awake the other ancients and rebuild their civilization. I realise I can just use the dev menu to recruit the pawns but is there a mod that make pawns of a certain race auto join your faction?

reddit.com
u/Silent_Reputation596 — 2 months ago

Floating Island Mod? Neoforge 1.21.1

I'm looking for a mod that adds large floating islands to the terrain generation while keeping the regular terrain below. Similar to the game "The Legend of Zelda: Tears of the Kingdom" where you have the regular overworld terrain but then if you up there are so many islands in the sky.

TLDR: I don't want a mod that replaces the terrain with floating islands, I want a mod that adds floating islands on top.

reddit.com
u/Silent_Reputation596 — 2 months ago

Fallout 4 or Cyberpunk 2077?

I have both games on steam and have played them both before. Right now they are both uninstalled. I want to play one of them but I can’t decide which and I don’t want to choose wrong cuz they take ages to download. Which on should I play? I like the futuristic punkiness of cyberpunk but I also like the weapon customization and settlement building of fallout 4

reddit.com
u/Silent_Reputation596 — 2 months ago

Fallout 4 or Cyberpunk 2077?

I have both games on steam and have played them both before. Right now they are both uninstalled. I want to play one of them but I can’t decide which and I don’t want to choose wrong cuz they take ages to download. Which on should I play? I like the futuristic punkiness of cyberpunk but I also like the weapon customization and settlement building of fallout 4

reddit.com
u/Silent_Reputation596 — 2 months ago