Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / CubeEditor.cs
Created April 21, 2020 14:19
Unity : Can i see an example of [ExecuteInEditMode] and [SelectionBase] ?
[ExecuteInEditMode]
[SelectionBase]
public class CubeEditor : MonoBehaviour
{
[SerializeField][Range(1f, 20f)] float gridSize = 10f;
TextMesh textMesh;
private void Start()
@openroomxyz
openroomxyz / EnemyMovement.cs
Created April 21, 2020 14:17
Unity : How to start a Coroutine -s to excute something in same thread and not block it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMovement : MonoBehaviour
{
[SerializeField] List<Waypoint> path;
void Start()
{
@openroomxyz
openroomxyz / slider.cs
Created April 21, 2020 14:14
Unity : How to create slider in inspector? -> [Range(a,b)]
[SerializeField][Range(1f, 20f)] float gridSize = 10f;
@openroomxyz
openroomxyz / RequireComponent.cs
Created April 21, 2020 14:13
Unity : How do mark that a script requires on gameObject other script?
[RequireComponent(typeof(Waypoint))]
@openroomxyz
openroomxyz / LogWarning.cs
Created April 21, 2020 14:12
Unity : How to log a warning?
Debug.LogWarning("This is text of warning!"); //loging a Warning
@openroomxyz
openroomxyz / findChangeColor.cs
Created April 21, 2020 14:10
Unity : How to find a children by name of current gameObject and change it’s color?
MeshRenderer topMeshRenerer = transform.Find("Top").GetComponent<MeshRenderer>();
topMeshRenerer.material.color = color;
//Note : Children children, not children of children’s.
@openroomxyz
openroomxyz / DestroyAndParticle.cs
Created April 21, 2020 14:07
Unity : How do we destroy gameObject and particle effect on it on destroy?
void KillEnemy()
{
ParticleSystem vfx = Instantiate(deathParticlePrefab, transform.position, Quaternion.identity);
vfx.Play();
float destroyDelay = vfx.main.duration;
Destroy(vfx.gameObject, destroyDelay);
//destroy patciles
Destroy(gameObject);
}
@openroomxyz
openroomxyz / GameObjectAsChildToOther
Created April 21, 2020 14:05
Unity : How do you add gameObject as child to other?
[SerializeField] GameObject towerParentTransform;
private void InstantiateNewTower(Waypoint baseWaypoint)
{
var newTower = Instantiate(towerPrefab, baseWaypoint.transform.position, Quaternion.identity);
newTower.transform.parent = towerParentTransform.transform; //THIS LINE
}
//or better
@openroomxyz
openroomxyz / EnemyAI.cs
Created April 21, 2020 14:02
Unity : How to NavMeshAgent?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyAI : MonoBehaviour
{
[SerializeField] Transform target; // We care where player is.
NavMeshAgent navMeshAgent;
// Start is called before the first frame update
@openroomxyz
openroomxyz / Weapon.cs
Created April 21, 2020 13:53
Unity : Can i see Raycast example?
public class Weapon : MonoBehaviour
{
[SerializeField] Camera FPCamera;
[SerializeField] float range = 100f;
[SerializeField] float damage = 30f;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
Shoot();