Você está na página 1de 6

OPERADORES

Operador unário ! (negação lógica).


Operadores binários & (AND lógico), | (OR lógico) e ^ (OR exclusivo lógico). Esses
operadores sempre avaliam os dois operandos.
Operadores binários && (AND lógico condicional) e || (OR lógico condicional). Esses
operadores avaliam o operando à direita apenas se for necessário.

-----------------------------x-----------------------x--------------------------

Debug.Log is a simple command that just prints a message to Unity’s console


output.

-----------------------------x-----------------------x--------------------------

Forma que a unity mostra as variáveis no inspector.

Unity creates the Inspector label by introducing a space wherever a capital


letter occurs in the variable name.

-----------------------------x-----------------------x--------------------------

Carregar cena.

SceneManager.LoadScene("cena de testes", LoadSceneMode.Additive);

-----------------------------x-----------------------x--------------------------

ROTATE.

gameobject.transform.Rotate(xAngle, yAngle, zAngle, Space.Self);


-----------------------------x-----------------------x--------------------------

Colliders
On the first physics update where the collision is detected, the
OnCollisionEnter function is called. During updates where contact is maintained,
OnCollisionStay is called and finally, OnCollisionExit indicates that contact
has been broken. Trigger colliders call the analogous OnTriggerEnter,
OnTriggerStay and OnTriggerExit functions. Note that for 2D physics, there are
equivalent functions with 2D appended to the name, eg, OnCollisionEnter2D.

Para verificar colisões o gameObject que vai detectar a colisão(ou seja, o


gameobject que vai carregar o código, ou seja o gameobject que será referendado
com NÂO sendo o outro) deve ter um box collider 2d marcado como is triger e deve
ter tambem um rigidibody do tipo kinematic.

void OnTriggerEnter2D(Collider2D outro)


{
if (outro.gameObject.name == "BallSprite")
{
Debug.Log("encostou na bola");
}
}
-----------------------------x-----------------------x--------------------------

Nome do Objeto: gameObject.name


Tag do Objeto: gameObject.tag

Printar nome do Objeto: Debug.Log("Hello: " + gameObject.name);

Printar nome do Objeto: Print("Hello: " + gameObject.name);


//criei uma variável pra poder alocar um objeto qualquer através do inspector.
public GameObject nome;

// Start is called before the first frame update


void Start()
{
Debug.Log(nome.gameObject.name);

-----------------------------x-----------------------x--------------------------

CONTROLAR COMPONENTES ATRAVÉS DE VARIÁVEIS.


Voçe consegue controlar todos os compontentes do seu inspector através do seu
script. Mas para controlar componentes que não façam parte do seu script você
precisa referenciar esses componentes. E pra isso se usa o Getcomponent. Uma
outra opção é declarar uma variável pública e depois arrastar o componente que
você quer alterar pra dentro do inspector.

void Start()
{
Transform mudar = GetComponent<Transform>();

mudar.transform.localPosition = new Vector3(0,2.5f,0);


}

-----------------------------x-----------------------x--------------------------

RECEBER VALORES DE VARIÁVEIS EM OUTROS SCRIPTS.


public GameObject obj_velocidade;
public float velocidade;

// Start is called before the first frame update


void Start()
{
velocidade = obj_velocidade.GetComponent<raise_lower>().vel_reel;

print(velocidade);

-----------------------------x-----------------------x--------------------------
TIMER

public float contagem;


float valordacontagem;

// Start is called before the first frame update


void Start()
{
valordacontagem = contagem;
}

// Update is called once per framKe


void Update()
{
if (contagem > 0)
{
contagem = contagem - Time.deltaTime;
}
else
{
contagem = 0;

//Colocar aqui o que vc quer que aconteça quando o cronômetro chegar a zero.
}

-----------------------------x-----------------------x--------------------------

GERAR NUMEROS RANDÔMICOS

Return a random float number between min [inclusive] and max [inclusive].

Variável = Random.Range(0, 10);

pode ser usado de várias formas, inclusive em vector 3.

-----------------------------x-----------------------x---------------------------x--------

CÓDIGO PRA CRIAR CLASSES, GERAR OBJETOS E O NEW OBJETO.

public class teste_script : MonoBehaviour


{
public familia primeira;

void Start()
{
primeira = new familia();
primeira.nome = "familia pereira";
print(primeira.nome);
}

public class familia


{
public string nome;
public string membros;
}

-----------------------------x-----------------------x--------------------------
Como dazer uma imagem deslizar dentro dela mesma nos 360 graus.

Primeiro crie uma rawimage.


Depois crie um material e configure o shader dele como legacy
shader/transparency/difuse.
Configure o sprite que você vai jogar dentro do material com o texture type
Defaut, e o Wrap mode como repeat.
Jogue o sprite dentro do material e depois jogue o material dentro da Raw image.

No código manipule a transião da raw image através do código:


“suaRawImagem”.uvRect = new Rect(0, 0, 0, 0);

-----------------------------x-----------------------x--------------------------
CÓDIGO PARA O RAISE

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class raise_script : MonoBehaviour


{
public float cabo = 1750.0f;
public Image cabo_barra;
public Text cabo_info_txt;
public bool libera_raise = false;

void Start()
{

void Update()
{
if (libera_raise == true)
{
cabo = cabo - 15.0f * Time.deltaTime;
}
cabo_barra.fillAmount = cabo / 1750;
cabo_info_txt.text = cabo.ToString("0000");
}

public void raise_clickdown()


{
if (cabo_barra.fillAmount > 0)
{
libera_raise = true;
}
else
{
libera_raise = false;
}
}

public void raise_clickup()


{
libera_raise = false;
}

-----------------------------x-----------------------x--------------------------
Alinhar Main Camera ou scene view um com o outro.

Com a camera em questão sececionada, clique na aba GameObject e clique em “align whit view”
para alinhar a camera com o que está mostrando na cena ou em “aligh view with selected” para
alinhar a cena com o que esta mostrando na camera.

-----------------------------x-----------------------x--------------------------

Rigidbody.drag
Drag can be used to slow down an object. The higher the drag the more the object slows down.

Rigidbody.angularDrag
Angular drag can be used to slow down the rotation of an object. The higher the drag the
more the rotation slows down.

-----------------------------x-----------------------x--------------------------

Transform.parent
Changing the parent will modify the parent-relative position, scale and rotation
but keep the world space position, rotation and scale the same.

//Makes the GameObject "newParent" the parent of the GameObject "player".


player.transform.parent = newParent.transform;

// Detaches the transform from its parent.


transform.parent = null;

-----------------------------x-----------------------x--------------------------

A Quaternion is a very special way to express a rotation. It uses 4 values


(x,y,z,w) which has nothing to do with angle-values. If you want to specify
euler angles, you have to use Quaternion.Euler like this:

player.transform.rotation = Quaternion.Euler(data.Xrotation, data.Yrotation, data.Zrotation);

-----------------------------x-----------------------x--------------------------

Converter String para diversos formatos.

Here's an example for you of how to retrieve data from UI inputfield;

InputField input;
int integer_Value_we_Want;
integer_Value_we_Want = int.Parse(input.text); //for integer
integer_Value_we_Want = float.Parse(input.text); //for float
integer_Value_we_Want = double.Parse(input.text); //for double
-----------------------------x-----------------------x--------------------------
-----------------------------x-----------------------x--------------------------

Converter float em INT

variávelINT = (int)variávelFloat;

-----------------------------x-----------------------x--------------------------

Destroy um objeto depois de 30 segundos.


public float timerdestroy = 30.0F;

// Start is called before the first frame update


void Start()
{

// Update is called once per frame


void Update()
{
if (timerdestroy < 0)
{
Destroy(this.gameObject);
}
else
{
timerdestroy -= Time.deltaTime;
}
}

-----------------------------x-----------------------x--------------------------

VERIFICAR SE UM OBJETO ESTÁ ATIVO OU NÃO

if (objeto_a_ser_verificado.activeSelf == true)

{
// Oque deve ser feito
}

Você também pode gostar