Professional Documents
Culture Documents
Translate: Transform Xvalue Zvalue
Translate: Transform Xvalue Zvalue
transform.Translate(xValue, 0, zValue);
Methods
void Start()
{
PrintInstructions();
}
void PrintInstructions()
{
Debug.Log("Welcome to the game");
Debug.Log("Be afraid of walls!");
Debug.Log("Move your player with WASD or arrow keys");
}
void MovePlayer()
{
float xValue = Input.GetAxis("Horizontal") * Time.deltaTime *
moveSpeed;
float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(xValue, 0, zValue);
}
}
GetComponent<MeshRenderer>().material.color = Color.yellow;
int hits = 0;
private void OnCollisionEnter(Collision other)
{
hits++;
Debug.Log("You've bumped into a thing this many times: " + hits);
}
Time.time = sa numere timpul din joc (alt C# Script pt obstacolul ce trebuie sa cada)
If in time.time
Cum faci un obiect invizibil si sa zboare iar dupa 3 secunde sa cada si sa fie vizibil
{
MeshRenderer renderer;
Rigidbody rigidbody;
[SerializeField] float timeToWait = 5f;
renderer.enabled = false;
rigidbody.useGravity = false;
}
}
}
}
If pt a baga taste
void Update()
{
ProcessThrust();
ProcessRotation();
}
void ProcessRotation()
{
if (Input.GetKey(KeyCode.A))
{
Debug.Log("Rotation Left");
}
else if (Input.GetKey(KeyCode.D))
{
Debug.Log("Rotation Right");
}
}
void ProcessRotation()
{
if (Input.GetKey(KeyCode.A))
{
ApplyRotation(rotationThrust);
}
else if (Input.GetKey(KeyCode.D))
{
ApplyRotation(-rotationThrust);
}
}
AudioSource audioSource;
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("This thing is friendly");
break;
case "Finish":
Debug.Log("Congrats, yo, you finish!");
break;
case "Fuel":
Debug.Log("YOU ARE FUEL");
break;
default:
Debug.Log("You suck!!!!!!!!!!!!!");
break;
}
using UnityEngine;
using UnityEngine.SceneManagement;
default:
ReloadLevel();
break;
}
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
case "Finish":
LoadNextLevel();
break;
case "Fuel":
Debug.Log("YOU ARE FUEL");
break;
default:
ReloadLevel();
break;
}
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
default:
Invoke("ReloadLevel ", 2f);
break;
Sa nu mai poti misca jucatorul dupa ce atingi obstacolul, dar sa revina la inceputul lvl dupa 2 secunde
default:
StartCrashSequence();
break;
}
}
void StartCrashSequence()
{
GetComponent<Move>().enabled = false;
Invoke("ReloadLevel", 2f);
}
Acelasi lucru ca mai sus, play la mai multe sunete cand atingi dif obiecte (ultimele 2 linii trebuie puse
in locurile potrivite
void Start()
{
audioSource = GetComponent<AudioSource>();
}
audioSource.PlayOneShot(success);
audioSource.PlayOneShot(crash);