UNITY RANDOM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Windows;
public class script_soal : MonoBehaviour{
int ke=0;
int score=0;
int bobot=10;
int jd=10;
string jawabanb4="";
string[] arA ;
string[] arB ;
string[] arC ;
string[] arD ;
string[] arE ;
string[] arS ;
string[] arJ ;
string[] arI ;
Texture2D myTexture;
List<int> ACAK = new List<int>();
void startAcak(){
for(int i = 0; i < jd; i++){
Pengacakan(jd);
}
Debug.Log("PJ="+ACAK.Count);
for(int i = 0; i < ACAK.Count; i++){
Debug.Log("Acak:"+i+"="+ACAK[i]);
}
}
void Pengacakan(int r) {
int ack = Random.Range (0, r);
while(ACAK.Contains(ack)) {
ack = Random.Range (0, r);
}
ACAK.Add(ack);
}
//======================================================
void Start() {
startAcak();
Debug.Log("score="+score.ToString()+"#"+ke.ToString());
loadsoal();
updateIsi("");
}
void Update() {
}
public void updateIsi(string jwb){
if(ke>=jd){
string hsl="?";
if (score<50){hsl="Anda harus rajin belajar....";}
else if (score<=80){hsl="Anda sudah Pintar...Pertahankan...";}
else if (score<=100){hsl="Anda Sangat Pintar....Selamat..!";}
Debug.Log("HASIL."+hsl);
GlobalVariables.Set("hasil", hsl);
GlobalVariables.Set("score", score);
GlobalVariables.Set("judul", "SCORE LAJU KIMIA");
UnityEngine.SceneManagement.SceneManager.LoadScene("menu_hasil");
ke=0;
}
else{
int ack=ACAK[ke];
Debug.Log("Soal ke-"+ke+" menjadi Soal ke-"+ack);
int no=ke+1;
string jA=arA[ack];
string jB=arB[ack];
string jC=arC[ack];
string jD=arD[ack];
string jE=arE[ack];
string soal=no.ToString()+"."+arS[ack];
string img=arI[ack];
GameObject.Find("pilA").GetComponentInChildren<Text>().text =jA;
GameObject.Find("pilB").GetComponentInChildren<Text>().text =jB;
GameObject.Find("pilC").GetComponentInChildren<Text>().text =jC;
GameObject.Find("pilD").GetComponentInChildren<Text>().text =jD;
GameObject.Find("pilE").GetComponentInChildren<Text>().text =jE;
GameObject.Find("txtSoal").GetComponentInChildren<Text>().text =soal;
if(ke>0){
if(jwb==jawabanb4){
score=score+bobot;
}
Debug.Log("HASIL."+ke.ToString()+"="+jwb+"=="+jawabanb4+"=>"+score.ToString()+"@IMAGE="+img+".jpg");
}
Sprite spriteIMG = Resources.Load <Sprite>("Images/"+img);
GameObject _image = GameObject.Find ("imgsoal");
_image.GetComponentInChildren<Image>().sprite =spriteIMG;
jawabanb4=arJ[ack];
Debug.Log("score="+score.ToString()+"#"+ke.ToString()+"."+soal+"#"+jawabanb4);
ke=ke+1;
}//else
}
public void Buka(string al){
Application.LoadLevel (al);
}
public void Keluar(){
Application.Quit();
}
public void SendMail(string al){
Application.OpenURL("mailto:"+al);
}
void loadsoal(){
arA= new string[jd];
arB= new string[jd];
arC= new string[jd];
arD= new string[jd];
arE= new string[jd];
arS= new string[jd];
arJ= new string[jd];
arI= new string[jd];
int n=0;
arS[n]="Siapa Presiden Sekarang ?";
arA[n]=" A. Suharto";
arB[n]=" B. Jokowi";
arC[n]=" C. SBY";
arD[n]=" D. Megawati";
arE[n]=" E. Sukarno";
arI[n]="A";//namafile gambar tanpa extensi
arJ[n]="B";n=n+1;
arS[n]="Siapakah Presiden yang ke 2";
arA[n]=" A. Jokowi";
arB[n]=" B. Suharto";
arC[n]=" C. Susilo Bambang Yudhoyono";
arD[n]=" D. Megawati";
arE[n]=" E. Sukarno";
arI[n]="B";
arJ[n]="B";n=n+1;
arS[n]="Siapakah Presiden yang ke 1";
arA[n]=" A. Sukarno";
arB[n]=" B. Jokowi";
arC[n]=" C. SBY";
arD[n]=" D. Megawati";
arE[n]=" E. Suharto";
arI[n]="C";
arJ[n]="A";n=n+1;
arS[n]="Siapakah Presiden yang ke 4";
arA[n]=" A. Prof. Ir. Eng. habibie";
arB[n]=" B. Jokowi";
arC[n]=" C. BJ Habibie";
arD[n]=" D. Megawati";
arE[n]=" E. Sukarno";
arI[n]="D";
arJ[n]="D";n=n+1;
arS[n]="Siapakah Presiden yang ke 6";
arA[n]=" A. Susilo Bambang Yudhoyono";
arB[n]=" B. Sukarno";
arC[n]=" C. Joko Widodo";
arD[n]=" D. Megawati";
arE[n]=" E. Suharto";
arI[n]="E";
arJ[n]="C";n=n+1;
arS[n]="Siapa Presiden Sekarang ??";
arA[n]=" A. Suharto";
arB[n]=" B. Jokowi";
arC[n]=" C. SBY";
arD[n]=" D. Megawati";
arE[n]=" E. Sukarno";
arI[n]="F";
arJ[n]="B";n=n+1;
arS[n]="Siapakah Presiden yang ke 2 ??";
arA[n]=" A. Jokowi";
arB[n]=" B. Suharto";
arC[n]=" C. Susilo Bambang Yudhoyono";
arD[n]=" D. Megawati";
arE[n]=" E. Sukarno";
arI[n]="G";
arJ[n]="B";n=n+1;
arS[n]="Siapakah Presiden yang ke 1 ??";
arA[n]=" A. Sukarno";
arB[n]=" B. Jokowi";
arC[n]=" C. SBY";
arD[n]=" D. Megawati";
arE[n]=" E. Suharto";
arI[n]="H";
arJ[n]="A";n=n+1;
arS[n]="Siapakah Presiden yang ke 4 ??";
arA[n]=" A. Prof. Ir. Eng. habibie";
arB[n]=" B. Jokowi";
arC[n]=" C. BJ Habibie";
arD[n]=" D. Megawati";
arE[n]=" E. Sukarno";
arI[n]="I";
arJ[n]="D";n=n+1;
arS[n]="Siapakah Presiden yang ke 6 ??";
arA[n]=" A. Susilo Bambang Yudhoyono";
arB[n]=" B. Sukarno";
arC[n]=" C. Joko Widodo";
arD[n]=" D. Megawati";
arE[n]=" E. Suharto";
arI[n]="J";
arJ[n]="C";n=n+1;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class script_hasil : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
string hasil= GlobalVariables.Get<string>("hasil");
string judul= GlobalVariables.Get<string>("judul");
int score= GlobalVariables.Get<int>("score");
Debug.Log("score "+score.ToString()+"#"+hasil+"#"+judul);
GameObject.Find("txtjudul").GetComponentInChildren<Text>().text =judul;
GameObject.Find("txtscore").GetComponentInChildren<Text>().text =score.ToString();
GameObject.Find("txthasil").GetComponentInChildren<Text>().text =hasil;
}
// Update is called once per frame
void Update()
{
}
public void Buka(string al){
Application.LoadLevel (al);
}
}
using System.Collections.Generic;
///https://forum.unity.com/threads/unity-beginner-loadlevel-with-arguments.180925/
/// <summary>
/// A simple static class to get and set globally accessible variables through a key-value approach.
/// </summary>
/// <remarks>
/// <para>Uses a key-value approach (dictionary) for storing and modifying variables.</para>
/// <para>It also uses a lock to ensure consistency between the threads.</para>
/// </remarks>
public static class GlobalVariables{
private static readonly object lockObject = new object();
private static Dictionary<string, object> variablesDictionary = new Dictionary<string, object>();
/// <summary>
/// The underlying key-value storage (dictionary).
/// </summary>
/// <value>Gets the underlying variables dictionary</value>
public static Dictionary<string, object> VariablesDictionary => variablesDictionary;
/// <summary>
/// Retrieves all global variables.
/// </summary>
/// <returns>The global variables dictionary object.</returns>
public static Dictionary<string, object> GetAll()
{
return variablesDictionary;
}
/// <summary>
/// Gets a variable and casts it to the provided type argument.
/// </summary>
/// <typeparam name="T">The type of the variable</typeparam>
/// <param name="key">The variable key</param>
/// <returns>The casted variable value</returns>
public static T Get<T>(string key)
{
if (variablesDictionary == null || !variablesDictionary.ContainsKey(key))
{
return default(T);
}
return (T)variablesDictionary[key];
}
/// <summary>
/// Sets the variable, the existing value gets overridden.
/// </summary>
/// <remarks>It uses a lock under the hood to ensure consistensy between threads</remarks>
/// <param name="key">The variable name/key</param>
/// <param name="value">The variable value</param>
public static void Set(string key, object value)
{
lock (lockObject)
{
if (variablesDictionary == null)
{
variablesDictionary = new Dictionary<string, object>();
}
variablesDictionary[key] = value;
}
}
}
UNITY RANDOM
Reviewed by ADIARRAY
on
22.33
Rating:
Tidak ada komentar: