Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Transform.

Translate = trebuie pus ca sa stie jocul pe cine muta

transform.Translate(xValue, 0, zValue);

SerializeField = apare in inspector si e mai usor de observant

 [SerializeField] float moveSpeed = 10f;

Input.GetAxis(“Horizontal”) = sa bagi butoane pt controlat mutatul (Input Manager)

float xValue = Input.GetAxis("Horizontal");

Time.deltaTime = sa calibreze framurile pt toate pc urile

[SerializeField] float moveSpeed = 10f;

float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;

cinemachinebrain = pune mai multe camera (add component)

Methods

    void Start()
    {
        PrintInstructions();
    }

    // Update is called once per frame


    void Update()
    {
        MovePlayer();
    }

    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);
    }
}

RigidBody = sa pastreze legile fizicii (add component)

Box collision = sa se loveasca de pereti (add component)

OnCollisionEnter = sa apara mesajul cand se loveste de pereti (alt C# Script pt walls)

public class ObjectHit : MonoBehaviour


{
    private void OnCollisionEnter(Collision other)
    {
        Debug.Log("Bumped into a wall");  
    }
}

GetComponent = sa schimbe culoarea un obiect cand e atins (C# Script de la walls)

GetComponent<MeshRenderer>().material.color = Color.yellow;

Scorer = Sa tina scorul loviturilor (alt C# Script pus pe player)

    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)

    // Start is called before the first frame update


    void Start()
    {
       
    }

    // Update is called once per frame


    void Update()
    {
        Debug.Log(Time.time);
    }

If in time.time

    [SerializeField] float timeToWait = 5f;


    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame


    void Update()
    {
        if(Time.time > timeToWait)
        {
            Debug.Log("3 seconds has elapsed");
        }
    }

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;

    // Start is called before the first frame update


    void Start()
    {
        renderer = GetComponent<MeshRenderer>();
        rigidbody = GetComponent<Rigidbody>();

        renderer.enabled = false;
        rigidbody.useGravity = false;

    }

    // Update is called once per frame


    void Update()
    {
        if(Time.time > timeToWait)
        {
            renderer.enabled = true;
            rigidbody.useGravity = true;
        }
    }
}

Cand cate obiectul sa nu se puna ca lovitura

    private void OnCollisionEnter(Collision other)


    {  
        if(other.gameObject.tag == "Player" )
        {
            GetComponent<MeshRenderer>().material.color = Color.black;      
        }

    }

Apare hit cand lovesti de mai multe ori acelasi ob

public class ObjectHit : MonoBehaviour


{
    private void OnCollisionEnter(Collision other)
    {  
        if(other.gameObject.tag == "Player" )
        {
            GetComponent<MeshRenderer>().material.color = Color.black;  
            gameObject.tag = "Hit";    
        }

    }
}

Tine scorul doar prima data cnad loveste un obiect

public class Scorer : MonoBehaviour


{
    int hits = 0;
   
    private void OnCollisionEnter(Collision other)
    {
        if(other.gameObject.tag != "Hit")
        {
            hits++;
            Debug.Log("You've bumped into a thing this many times: " + hits);
        }
    }
}

Rotate = sa se roteasca un obiect (alt c# script)

    [SerializeField] float xRotate = 0;


    [SerializeField] float yRotate = 2;
    [SerializeField] float zRotate = 0;
   
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame


    void Update()
    {
        transform.Rotate(xRotate, yRotate, zRotate);
       
    }

If pt a baga taste

    void Update()
    {
        ProcessThrust();
        ProcessRotation();
    }

    private void ProcessThrust()


    {
        if (Input.GetKey(KeyCode.Space))
        {
            Debug.Log("Pressed SPACE - Thrusting");
        }
    }

    void ProcessRotation()
    {
        if (Input.GetKey(KeyCode.A))
        {
            Debug.Log("Rotation Left");
        }
        else if (Input.GetKey(KeyCode.D))
        {
            Debug.Log("Rotation Right");
        }
    }

Ctrl + . = creezi clasa noua daca selectezi ceva

sa arate mai clean treaba cu delta.time cand sunt mai multe

    void ProcessRotation()
    {
        if (Input.GetKey(KeyCode.A))
        {
            ApplyRotation(rotationThrust);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            ApplyRotation(-rotationThrust);
        }
    }

    void ApplyRotation(float rotationThisFrame)


    {
        transform.Rotate(Vector3.forward * rotationThisFrame *
Time.deltaTime);

freeze = in rigidbody apesi acolo sa nu se duca intr-o anumita directive

freezing rotation ca sa o facem manual sa nu se loveasca de obstacol si sa nu mai mearga deloc

void ApplyRotation(float rotationThisFrame)


    {
        rb.freezeRotation = true;
        transform.Rotate(Vector3.forward * rotationThisFrame *
Time.deltaTime);
        rb.freezeRotation = false;

sa porneasca audio cand dai play (e bun cand ai un singur sunet)

    AudioSource audioSource;

    // Start is called before the first frame update


    void Start()
    {
        rb = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
    }

    // Update is called once per frame


    void Update()
    {
        ProcessThrust();
        ProcessRotation();
       
    }

    private void ProcessThrust()


    {
        if (Input.GetKey(KeyCode.Space))
        {
            rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
            if(!audioSource.isPlaying)
            {
            audioSource.Play();
            }
        }
        else
        {
            audioSource.Stop();
        }

Game object hit cu switch

        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;
        }

Sa revina la start dup ace loveste ceva (e atasat la scriptul de deasupra)

using UnityEngine;
using UnityEngine.SceneManagement;
     
      default:
                ReloadLevel();
                break;
        }
    }

    void ReloadLevel()
    {
        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        SceneManager.LoadScene(currentSceneIndex);
    }

Cand termina nivelul sa treaca la urm

            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);

Dupa temrinarea ultimului lvl, revine la lvl 1

        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;


        int nextSceneIndex = currentSceneIndex + 1;
        if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
        {
            nextSceneIndex = 0;
        }
        SceneManager.LoadScene(nextSceneIndex);

Sa revina la nivel dupa lovitura dupa 2 secunde

            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);
    }

Sa puna play cand ai mai multe sunete

    [SerializeField] AudioClip mainEngine;


        if (Input.GetKey(KeyCode.Space))
        {
            rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
            if(!audioSource.isPlaying)
            {
            audioSource.PlayOneShot(mainEngine);
            }

Acelasi lucru ca mai sus, play la mai multe sunete cand atingi dif obiecte (ultimele 2 linii trebuie puse
in locurile potrivite

    [SerializeField] AudioClip crash;


    [SerializeField] AudioClip success;
    AudioSource audioSource;

    void Start()
    {
        audioSource = GetComponent<AudioSource>();
    }

        audioSource.PlayOneShot(success);
        audioSource.PlayOneShot(crash);

inTransitioning = cand e in tranzitie sa nu faca lucruri

    bool isTransitioning = false;


    private void OnCollisionEnter(Collision other)
    {
        if (isTransitioning) {return;}
    void StartCrashSequence()
    {
        isTransitioning = true;
        audioSource.Stop();
    void StartSuccessSequence()
    {
        isTransitioning = true;
        audioSource.Stop();

play particle cand lovesti ceva

    [SerializeField] ParticleSystem crashParticles;


    [SerializeField] ParticleSystem successParticles;
    void StartCrashSequence()
    {
        crashParticles.Play();
    void StartSuccessSequence()
    {
        successParticles.Play();

You might also like