Toggle GameObject Visibility – Unity
if(gameObject.activeSelf){ gameObject.SetActive(false); }else{ gameObject.SetActive(true); }
if(gameObject.activeSelf){ gameObject.SetActive(false); }else{ gameObject.SetActive(true); }
using UnityEngine; using UnityEngine.Windows.Speech; public class SpeechRecogniser: MonoBehaviour { protected DictationRecognizer dictationRecognizer; void Start() { } // CALL THIS FUNCTION WHEN YOU WANT TO START LISTENING TO DICTATION public void startDictationRequest(){ // THIS IS REALLY IMPORTANT!! // If you are using the MRTK and have phrase recognition running, then you can’t use both at once, … Read more
This one is super simple and is just if(text.Contains(“your words here”)){ do something; }
Basically you just need to access the material property of the Renderer component. public Material yourMaterial; gameobject.GetComponent<Renderer> ().material = yourMaterial;
Right, so classes have a number of methods in them and it can get a bit confusing as to when each of them are called, especially when you require a very specific sequence of events to occur. So let’s say that you are instantiating a prefab from a class method. yourPrefab yPre = Instantiate(yourPrefab, transform.position, transform.rotation); … Read more
Scriptable Objects have 2 major uses Saving and storing data during an editor session Saving data as an asset in our project for use at runtime Things to Note In the editor we can save data to the SO during edit and runtime In a deployed build we can only read the data from the … Read more
So what does this word “static” do to variables and methods? Well a couple of things. static variables and methods that are public are accessible from anywhere without having to first reference or instantiate the class that they are in. Note though that if they are private, they can not. They make variables class variables, … Read more
Unity have actually documented this really well here You might want to use the CrossPlatformInputManager which I have made a blog post about here
So these are classes that you write, that extend one of the Unity classes. There’s a good example on one of the Learn Unity tutorial site here. But basically you will create the class file like this: using UnityEngine; using System.Collections; //It is common to create a class to contain all of your //extension methods. This class must be static. public static class ExtensionMethods { //RULE 1 : extension methods must be declared static. //RULE 2 : The first parameter must have the keyword “this” //RULE 3 : Follow the “this” with the Class name that you are extending, // example, Vector3, Transform, Rigidbody //RULE 4 : Follow the class type with a variable name to use in the method // then just do whatever you need to in the method as per usual public static void ResetTransformation(this Transform trans) { trans.position = Vector3.zero; trans.localRotation = Quaternion.identity; trans.localScale = new Vector3(1, 1, 1); } … Read more
So I was watching a tutorial and the guys keeps banging on about classes being monobehaviour or not and I started wondering why he was making note of one that wasn’t monobehaviour. So I’ve looked it up on Unity and you can see the whole post here, but the main jist is this. MonoBehaviour is … Read more