heky
1
I’m attempting to reference a public variable of one script within another by using
FindObjectOfType ScriptName (); (for some reason the little carrots make “ScriptName” dissappear but the syntax in the code is correct)
and I’m receiving this error. Can anyone tell me:
A) Why this is happening?
B) How to fix it?
C) A better way to achieve what I’m trying to do?
It means you are calling a function that doesn’t exist.
The “FindObjectOfType” method is a static function for Objects meaning you don’t call “gameObject.FindObjectOfType” you instead call “GameObject.FindObjectOfType”.
Where “GameObject” is the class, “gameObject” is an instance of the GameObject class and is a variable of MonoBehaviours.
In your case, since your class doesn’t inherit from MonoBehaviour or Object you don’t have a function called FindObjectOfType so you need to call the static function of something that does ie GameObject.
Proper use of FindObjectOfType with your own class:
SomeClass myObject = GameObject.FindObjectOfType<SomeClass>();
heky
3
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public static class Noise {
public enum NormalizeMode {Local, Global};
public static float[,] GenerateNoiseMap(stuff) {
MapGenerator generator = FindObjectOfType<MapGenerator>();
The rest of the code is irrelevant. MapGenerator is the name of another script I’m attempting to pull.