Freitag, 14. Februar 2020

Unity 3d - change color - get current gameObject and change its color

image - see https://www.youtube.com/watch?v=_RIsfVOqTaE

using UnityEngine.UI;
..
public Image img;
...
img.color = Color.red; //



object - see https://learn.unity.com/tutorial/scripts-as-behaviour-components#

GetComponent<Renderer>().material.color = Color.red;





Unity 3d - get and set screen resolution

get:

          Debug.Log("Screen Width : " + Screen.width);
    Debug.Log("Screen Height : " + Screen.height);

set:

    Screen.SetResolution(1600,900,false);

...where 1600 is the width, 900 the height and finally a boolean to signalize the fullscreen mode.

Dienstag, 11. Februar 2020

Unity 3d - c# Awake and Start methods

see https://www.youtube.com/watch?v=4QdjoV63wjM

Awake() initializes private variables of an object once a startup.

When later on the object is gonna be enabled it will benefit of all settings made in Awake().
This will be unattended handled by Unity when the Start() script is being called.



Unity 3d - wait a few seconds / sleep

C# - How to wait a while in Unity 3d see https://docs.unity3d.com/ScriptReference/WaitForSeconds.html
...
StartCoroutine(TimeRoutine());
...
IEnumerator TimeRoutine()
{
       yield return new WaitForSeconds(3.0f); // wait 3 seconds within this TimeRoutine thread
       //load the next scene then for instance
}



Unity 3d - change scence how to

C#: how to switch to another scene in Unity 3d

using UnityEngine.SceneManagement;
..
SceneManager.LoadScene("myNextScene");

get current scene name:

Debug.Log(SceneManager.GetActiveScene().name.ToString());

get Scene:

private Scene view;
...
this.view = SceneManager.GetActiveScene();