UNITY BASIC CODE
LOAD Scene
https://gamedevbeginner.com/how-to-load-a-new-scene-in-unity-with-a-loading-screen/
void Start(){
LoadLevel(12);
}
public void LoadLevel(int level){
GlobalVariables.Set("currentLevelIndex", level);
UnityEngine.SceneManagement.SceneManager.LoadScene("Game");
}
=============================
void Start(){
int levelIndex = GlobalVariables.Get<int>("currentLevelIndex");
Debug.Log(levelIndex); // Outputs 12
}
using UnityEngine.SceneManagement;
void Update(){
if (Input.GetKey(KeyCode.Escape)){
SceneManager.LoadScene("Main Menu");
}
}
======================
using UnityEngine;
using UnityEngine.SceneManagement;
public class TestingScript : MonoBehaviour {
void Start(){
StaticClass.CrossSceneInformation = "Hello Scene2!";
SceneManager.LoadScene("Test2");
}
}
A new static class (not inheriting from monobehaviour) that holds information:
public static class StaticClass {
public static string CrossSceneInformation { get; set; }
}
A script attached to a game object in scene "Test2":
using UnityEngine;
public class TestingScript2: MonoBehaviour {
void Start (){
Debug.Log(StaticClass.CrossSceneInformation);
}
}
###############################
using UnityEngine.SceneManagement;
SceneManager.LoadScene("Scene name");
ATAU
using UnityEngine.SceneManagement;
int buildIndex = 0;
SceneManager.LoadScene(buildIndex);
using UnityEngine.SceneManagement;
public class LoadScene: MonoBehaviour{
public void LoadNextScene(){
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
==================================
https://gamedevbeginner.com/how-to-load-a-new-scene-in-unity-with-a-loading-screen/
void Start(){
LoadLevel(12);
}
public void LoadLevel(int level){
GlobalVariables.Set("currentLevelIndex", level);
UnityEngine.SceneManagement.SceneManager.LoadScene("Game");
}
=============================
void Start(){
int levelIndex = GlobalVariables.Get<int>("currentLevelIndex");
Debug.Log(levelIndex); // Outputs 12
}
using UnityEngine.SceneManagement;
void Update(){
if (Input.GetKey(KeyCode.Escape)){
SceneManager.LoadScene("Main Menu");
}
}
======================
using UnityEngine;
using UnityEngine.SceneManagement;
public class TestingScript : MonoBehaviour {
void Start(){
StaticClass.CrossSceneInformation = "Hello Scene2!";
SceneManager.LoadScene("Test2");
}
}
A new static class (not inheriting from monobehaviour) that holds information:
public static class StaticClass {
public static string CrossSceneInformation { get; set; }
}
A script attached to a game object in scene "Test2":
using UnityEngine;
public class TestingScript2: MonoBehaviour {
void Start (){
Debug.Log(StaticClass.CrossSceneInformation);
}
}
###############################
using UnityEngine.SceneManagement;
SceneManager.LoadScene("Scene name");
ATAU
using UnityEngine.SceneManagement;
int buildIndex = 0;
SceneManager.LoadScene(buildIndex);
using UnityEngine.SceneManagement;
public class LoadScene: MonoBehaviour{
public void LoadNextScene(){
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
==================================
Dictionary.LIST, ARRAY
private string[] _itemNames = new string[5] {"Sword", "Apple", "Apple", "Potion", "Potion"};
private bool[] _isStackable = new bool[5]{false, true, true, true, false};
void Start()
{
for(int i = 0; i < _itemNames.length; i++)
{
if(_isStackable[i] == false)
{
Debug.Log("Item " + i +" Is Not Stackable, Name : " + _itemNames[i]);
}
else if(_isStackable[i] == true)
{
Debug.log("Item " + i + " Is Stackable, Name: " + _itemNames[i]);
}
}
}
==================================
List<string> stringList = new List<string>{"string1", "string2"};
stringList.Count
List<int> numbers = new List<int>();
public int NewNumber(int r) {
int a = Random.Range (0, r);
if(!numbers.Contains(a)) {
numbers.Add(a);
}
return a;
}
//====================================
https://gyanendushekhar.com/2017/07/08/load-image-runtime-unity/
https://gyanendushekhar.com/2017/07/08/load-image-runtime-unity/
using UnityEngine;
using UnityEngine.UI;
public class LoadTexture : MonoBehaviour {
Texture2D myTexture;
void Start () {
myTexture = Resources.Load ("Images/SampleImage") as Texture2D;
GameObject rawImage = GameObject.Find ("RawImage");
rawImage.GetComponent<RawImage> ().texture = myTexture;
}
}
==========================================
using UnityEngine;
using UnityEngine.UI;
public class LoadSprite : MonoBehaviour {
Sprite sprite;
void Start () {
sprite = Resources.Load <Sprite>("Images/SampleSprite");
GameObject image = GameObject.Find ("Image");
image.GetComponent<Image>().sprite = sprite;
}
}
######################################
public GameObject txt;
txt.GetComponent<UnityEngine.UI.Text>().text = score.ToString();
public Text myText;
myText.text = "Enter the text value here!";
public class Example : MonoBehaviour{
public Text m_MyText;
void Start(){
m_MyText.text = "This is my text";
}
void Update(){
if (Input.GetKey(KeyCode.Space)){
m_MyText.text = "My text has now changed.";
}
}
}
++++++++++++++++++++++++++++++++++++
https://hub.packtpub.com/arrays-lists-dictionaries-unity-3d-game-development/
public float[] values;
void Start(){
values = new float[10];
values[1] = 5.0F;
foreach (float value in values){
print(value);
}
}
https://gamedevsolutions.com/find-gameobject-at-runtime/
GameObject objectToDestroy = GameObject.Find("Destroy Obj");
GameObject objectToDestroy = GameObject.FindWithTag("Bullet");
Debug.Log(objectToDestroy.name, objectToDestroy);
GameObject gun = player.transform.Find("Gun").gameObject;
GameObject cube3 = transform.Find("@Cube (single mesh)/Cube3").gameObject;
GameObject cube3 = transform.GetChild(0).GetChild(2).gameObject;
########################################################
https://youtu.be/dJjAluMUNes
Untuk AR hanya bisa di jalankan di IOS/Android/leap motion/oculus
https://stackoverflow.com/questions/37912521/how-to-build-vuforia-unity-project-as-a-windows-pc-standalone-app
jadi untuk exe gk bisa jalan AR nya...
_Untuk Build ke .apk_
masih ada kendala di ketidak sesuaian antara gradle 6.1.1 UNITY terhadap android java nya
(masih di cari hari ini...)
https://www.youtube.com/watch?v=VLPPj8J9MIM
https://answers.unity.com/questions/1846144/how-to-remove-androidenabler8-from-the-project.html
CommandInvokationFailure: Gradle build failed.
dPlayer/Tools\OpenJDK\Windows\bin\java.exe
-classpath gradle\lib\gradle-launcher-5.1.1.jar org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
CommandInvokationFailure: Gradle build failed.
lib\gradle-launcher-5.1.1.jar
https://www.codeprofessionally.com/gradle-build-failed-unity/
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-18.0.2.1
https://copyfuture.com/blogs-details/202112300730367964
https://forum.unity.com/threads/commandinvokationfailure-gradle-build-failed.479460/
https://forum.unity.com/threads/unity-2017-1-android-build-error.482738/
https://www.codeprofessionally.com/gradle-build-failed-unity/
https://www.codeprofessionally.com/gradle-build-failed-unity/
ANDROID API 4 7 11 33
+++++++++++++++++++++++++++++
JDK
C:\Program Files\Java\jdk1.8.0_341
ANDROID SDK LOCATION
C:\Users\adiarray\AppData\Local\Android\Sdk
NDK
D:\UNITYCODE\android-ndk-r19
Gradle
D:\UNITYCODE\gradle-6.9.2
<div>For Unity Version 2019 or 2020 <a href="https://dl.google.com/android/repository/android-ndk-r19-windows-x86_64.zip" target="_blank" rel="nofollow noopener"><b>Download NDK r19</b></a> .</div>
<div>For Unity Version 2021 or 2022 <a href="https://dl.google.com/android/repository/android-ndk-r21d-windows-x86_64.zip" target="_blank" rel="nofollow noopener"><b>Download NDK r21d</b></a> .</div>
ASLI:
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK
NDK
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle
CommandInvokationFailure: Gradle build failed.
\OpenJDK\bin\java.exe gradle\lib\gradle-launcher-6.1.1.jar-Xmx4096m assembleRelease
private string[] _itemNames = new string[5] {"Sword", "Apple", "Apple", "Potion", "Potion"};
private bool[] _isStackable = new bool[5]{false, true, true, true, false};
void Start()
{
for(int i = 0; i < _itemNames.length; i++)
{
if(_isStackable[i] == false)
{
Debug.Log("Item " + i +" Is Not Stackable, Name : " + _itemNames[i]);
}
else if(_isStackable[i] == true)
{
Debug.log("Item " + i + " Is Stackable, Name: " + _itemNames[i]);
}
}
}
==================================
List<string> stringList = new List<string>{"string1", "string2"};
stringList.Count
List<int> numbers = new List<int>();
public int NewNumber(int r) {
int a = Random.Range (0, r);
if(!numbers.Contains(a)) {
numbers.Add(a);
}
return a;
}
//====================================
https://gyanendushekhar.com/2017/07/08/load-image-runtime-unity/
https://gyanendushekhar.com/2017/07/08/load-image-runtime-unity/
using UnityEngine;
using UnityEngine.UI;
public class LoadTexture : MonoBehaviour {
Texture2D myTexture;
void Start () {
myTexture = Resources.Load ("Images/SampleImage") as Texture2D;
GameObject rawImage = GameObject.Find ("RawImage");
rawImage.GetComponent<RawImage> ().texture = myTexture;
}
}
==========================================
using UnityEngine;
using UnityEngine.UI;
public class LoadSprite : MonoBehaviour {
Sprite sprite;
void Start () {
sprite = Resources.Load <Sprite>("Images/SampleSprite");
GameObject image = GameObject.Find ("Image");
image.GetComponent<Image>().sprite = sprite;
}
}
######################################
public GameObject txt;
txt.GetComponent<UnityEngine.UI.Text>().text = score.ToString();
public Text myText;
myText.text = "Enter the text value here!";
public class Example : MonoBehaviour{
public Text m_MyText;
void Start(){
m_MyText.text = "This is my text";
}
void Update(){
if (Input.GetKey(KeyCode.Space)){
m_MyText.text = "My text has now changed.";
}
}
}
++++++++++++++++++++++++++++++++++++
https://hub.packtpub.com/arrays-lists-dictionaries-unity-3d-game-development/
public float[] values;
void Start(){
values = new float[10];
values[1] = 5.0F;
foreach (float value in values){
print(value);
}
}
https://gamedevsolutions.com/find-gameobject-at-runtime/
GameObject objectToDestroy = GameObject.Find("Destroy Obj");
GameObject objectToDestroy = GameObject.FindWithTag("Bullet");
Debug.Log(objectToDestroy.name, objectToDestroy);
GameObject gun = player.transform.Find("Gun").gameObject;
GameObject cube3 = transform.Find("@Cube (single mesh)/Cube3").gameObject;
GameObject cube3 = transform.GetChild(0).GetChild(2).gameObject;
########################################################
https://youtu.be/dJjAluMUNes
Untuk AR hanya bisa di jalankan di IOS/Android/leap motion/oculus
https://stackoverflow.com/questions/37912521/how-to-build-vuforia-unity-project-as-a-windows-pc-standalone-app
jadi untuk exe gk bisa jalan AR nya...
_Untuk Build ke .apk_
masih ada kendala di ketidak sesuaian antara gradle 6.1.1 UNITY terhadap android java nya
(masih di cari hari ini...)
https://www.youtube.com/watch?v=VLPPj8J9MIM
https://answers.unity.com/questions/1846144/how-to-remove-androidenabler8-from-the-project.html
CommandInvokationFailure: Gradle build failed.
dPlayer/Tools\OpenJDK\Windows\bin\java.exe
-classpath gradle\lib\gradle-launcher-5.1.1.jar org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
CommandInvokationFailure: Gradle build failed.
lib\gradle-launcher-5.1.1.jar
https://www.codeprofessionally.com/gradle-build-failed-unity/
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files\Java\jdk-18.0.2.1
https://copyfuture.com/blogs-details/202112300730367964
https://forum.unity.com/threads/commandinvokationfailure-gradle-build-failed.479460/
https://forum.unity.com/threads/unity-2017-1-android-build-error.482738/
https://www.codeprofessionally.com/gradle-build-failed-unity/
https://www.codeprofessionally.com/gradle-build-failed-unity/
ANDROID API 4 7 11 33
+++++++++++++++++++++++++++++
JDK
C:\Program Files\Java\jdk1.8.0_341
ANDROID SDK LOCATION
C:\Users\adiarray\AppData\Local\Android\Sdk
NDK
D:\UNITYCODE\android-ndk-r19
Gradle
D:\UNITYCODE\gradle-6.9.2
<div>For Unity Version 2019 or 2020 <a href="https://dl.google.com/android/repository/android-ndk-r19-windows-x86_64.zip" target="_blank" rel="nofollow noopener"><b>Download NDK r19</b></a> .</div>
<div>For Unity Version 2021 or 2022 <a href="https://dl.google.com/android/repository/android-ndk-r21d-windows-x86_64.zip" target="_blank" rel="nofollow noopener"><b>Download NDK r21d</b></a> .</div>
ASLI:
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK
NDK
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK
C:\Program Files\Unity\Hub\Editor\2020.3.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle
CommandInvokationFailure: Gradle build failed.
\OpenJDK\bin\java.exe gradle\lib\gradle-launcher-6.1.1.jar-Xmx4096m assembleRelease
UNITY BASIC CODE
Reviewed by ADIARRAY
on
23.23
Rating:
Tidak ada komentar: