Why cant i find the other objects?

As Spiney says above, reference it by a master script, like this one I might use for my player:

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

// @kurtdekker - put this on the root of your player.
// It does NOTHING except give you quick access
// to other parts of the player.
//
// For instance, your player hierarchy might look like:
//
//    PlayerPrefab
//        VisibleAnimatedGeometry
//        Weapon1
//        Weapon2
//        DialogPopup

public class Player : MonoBehaviour
{
    // each of these things must be located
    // somewhere on this same hierarchy of GameObjects
    public PlayerMovement movement;

    public PlayerWeapon weapon;

    public PlayerDialog dialog;

    // any other stuff your player or enemy or whatever this thing is must do
}

NOTE: The above script has no code, just references to OTHER scripts that do the actual work.

In your spawner code:

// drag player prefab in here
public Player PlayerPrefab;
private Player PlayerInstance;

To instantiate:

PlayerInstance = Instantiate<Player>( PlayerPrefab, position, rotation);

That’s it. If you are not using this ultra ultra ultra simple strategy to keep stuff centralized and concentrated, you’re probably making things unnecessarily complicated for yourself.

Extend the above to each broad type of object: enemy, projectile, trap, door, etc.

Note how there is no “finding” going on.

1 Like