unity3d

Unity c#: making an array of class type equal to FindObjectOfType [closed]

*爱你&永不变心* 提交于 2021-02-05 09:41:05
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 1 year ago . Improve this question In my c# script I am working on, I have this code public class Attractor : MonoBehaviour { public Rigidbody rb; private void FixedUpdate() { //physics code Attractor[] attractors = FindObjectOfType<Attractor>(); } I am currently getting an error saying Error

Destroying assets is not permitted to avoid data loss

◇◆丶佛笑我妖孽 提交于 2021-02-05 09:38:12
问题 I'm running into trouble with my RemoveTail function which executes the code: destroy(gameObject). This snake game creates a clone of the my Snake prefab and I control the Snake's length by assigning a "tail" and deleting the "tail" gameobject if maxSize is reached. I understand that my error is due to the game deleting my tail which is a clone of the prefab instead of deleting an instance of Snake. Any ideas or suggestions on how I may resole this issue? Snake script public class Snake :

Destroying assets is not permitted to avoid data loss

瘦欲@ 提交于 2021-02-05 09:38:07
问题 I'm running into trouble with my RemoveTail function which executes the code: destroy(gameObject). This snake game creates a clone of the my Snake prefab and I control the Snake's length by assigning a "tail" and deleting the "tail" gameobject if maxSize is reached. I understand that my error is due to the game deleting my tail which is a clone of the prefab instead of deleting an instance of Snake. Any ideas or suggestions on how I may resole this issue? Snake script public class Snake :

Retrieve Data from Realtime Database with Action Callback

痴心易碎 提交于 2021-02-05 09:26:27
问题 I am trying to receive the JSON value from the Realtime Database of Firebase using Unity. I do the following: FirebaseDatabase.DefaultInstance .GetReference("Leaders").OrderByChild("score").GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.LogError("error in reading LeaderBoard"); return; } else if (task.IsCompleted) { Debug.Log("Received values for Leaders."); string JsonLeaderBaord = task.Result.GetRawJsonValue(); callback(JsonLeaderBaord); } } }); Trying to Read the

Retrieve Data from Realtime Database with Action Callback

青春壹個敷衍的年華 提交于 2021-02-05 09:26:00
问题 I am trying to receive the JSON value from the Realtime Database of Firebase using Unity. I do the following: FirebaseDatabase.DefaultInstance .GetReference("Leaders").OrderByChild("score").GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.LogError("error in reading LeaderBoard"); return; } else if (task.IsCompleted) { Debug.Log("Received values for Leaders."); string JsonLeaderBaord = task.Result.GetRawJsonValue(); callback(JsonLeaderBaord); } } }); Trying to Read the

Shuffle array in Unity

假装没事ソ 提交于 2021-02-05 08:50:08
问题 I want to shuffle the numbers in my array variable once, so I called my Shuffle method from Start() . I then attempt access the shuffled array from update, but I am unable to do so. How can I access it? Is there any other way to shuffle my array once, then use it forever? private System.Random _random = new System.Random(); float sec; float timecount; float starttime; void Start () { starttime = Time.time; int[] array = { 1, 2, 3, 4, 5, 6, 7, 8}; Shuffle(array); foreach (int value in array) {

How can I grab a reference of a game-object in a scene from a prefab

旧街凉风 提交于 2021-02-05 08:48:09
问题 currently I am working on a Equipment system that will Instantiate Game objects into the scene from a list, prior to this I was not using a Instantiation system with just keeping the Game Objects Active in the scene at all time. Now with Instantiating the Game Object(Prefab) I am running into the error of Loosing the References when I instantiate them, I have looked at various other articles before such as this Discussion here: However I am looking at alternative ways other than using Tags as

why GetComponent returns null reference for imageEffect?

五迷三道 提交于 2021-02-05 08:16:46
问题 this problem is unsolvable or what?i don't need to provide any code example it just doesn't work to anyone!and i don't know how its possible,you just have to try this : GetComponent<DepthOfField>().enabled = false; assume that we have a MainCamera object and we attach it a DepthOfField image effect Script.and we create another script named whatever and attach it to the MainCamera and in the whatever script we just call this: void Start() { GetComponent<DepthOfField>().enabled = false; }

How can I create an alias for a class, globally, in Unity?

非 Y 不嫁゛ 提交于 2021-02-05 08:07:19
问题 Right now, I am using "string" to enumerate a list of equipment slots on a character. I am also using "string" to enumerate the class type that the item can be equipped on. This makes all my methods where I get, remove, generate, etc. items involve having two string parameters that is an equipment slot and class type. What I really would like is to use 2 classes so that I have 2 strongly typed concepts for the slot and class_type. The problem is that string is a sealed class and thus I cannot

How can I create an alias for a class, globally, in Unity?

邮差的信 提交于 2021-02-05 08:06:15
问题 Right now, I am using "string" to enumerate a list of equipment slots on a character. I am also using "string" to enumerate the class type that the item can be equipped on. This makes all my methods where I get, remove, generate, etc. items involve having two string parameters that is an equipment slot and class type. What I really would like is to use 2 classes so that I have 2 strongly typed concepts for the slot and class_type. The problem is that string is a sealed class and thus I cannot