Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / ChangingColorProgramaticallyClassicRP.cs
Created April 19, 2020 19:10
Unity : How to set a color on basic Material pragmatically in classic RP?
GameObject g = .....
g.GetComponent<Renderer>().material.color = new Color(color.r, color.g, color.b, color.a);
@openroomxyz
openroomxyz / DependencyGraphSolver.cs
Last active April 19, 2020 16:13
Unity : How to find right order of instructions automatically with dependency graph [Example with interpolations]?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DependencyGraphSolver
{
public class DependencyGraphSolver
{
Dictionary<int, Node> nodes;
public DependencyGraphSolver()
@openroomxyz
openroomxyz / ScriptSelfInstancimatedObject.cs
Created April 18, 2020 20:02
Unity : How can a script itself creates gameobject at Runtime and attach itself to it or [Creating game-object directly from script that is not attracted to any game objects ]?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfInstanciated : MonoBehaviour
{
[RuntimeInitializeOnLoadMethod]
static void Init()
{
@openroomxyz
openroomxyz / SearchByTag.cs
Created April 18, 2020 19:36
Unity : How to find all the object in scene with certain tag?
GameObject[] arrayOfGameObjects = GameObject.FindGameObjectsWithTag("tag that we wish to search for");
@openroomxyz
openroomxyz / HowToQuitTheAplication.cs
Created April 18, 2020 19:12
Unity : How to quit the application? [It works only with build application it does not work inside Editor]
if(Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
@openroomxyz
openroomxyz / LockCursorMakeItInvisible.cs
Created April 18, 2020 15:44
Unity : How to lock the cursor and make it invisible ?
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
@openroomxyz
openroomxyz / RunScriptInEditModeAndReciveInput.cs
Last active July 14, 2020 11:15
Unity : How can i run a script in in edit mode (Not Runtime) when i select some object, and i wish to receive user input (Edit update loop) and Instantiate and object on key-press ?
using UnityEditor;
using UnityEngine;
//How can i run a script in at at edit time (Not Runtime) when object is selected, and recive user input (Edit update loop) ?
//Editor scripts have to be in folder named Editor
//[CustomEditor(typeof(GameObject))] ensures that this peace of code will run only when we have GameObject selected so we are save to cast object to GameObject [selectedTarget = (GameObject)target;]
[CustomEditor(typeof(GameObject))] //This is custom editor for the type GameObject ( This script will kick in when we have game object selected )
public class CubeEditor : Editor
{
@openroomxyz
openroomxyz / InstanciatingThePrefabFromResouces.cs
Created April 18, 2020 12:14
Unity : How can i Instantiate Prefab by filename from File inside the folder Resources ?
GameObject instanciatedCube = (GameObject)PrefabUtility.InstantiatePrefab(Resources.Load("Cube"));
//Prefab has to be in folder named Resources
@openroomxyz
openroomxyz / BooleanWave.py
Created April 16, 2020 15:21
Blender Python : How to create a Wave with Boolean :) ?
import bpy
import uuid
import math
import random
def create_a_cube(name, position, set_rotation, scale):
# Create a simple cube.
bpy.ops.mesh.primitive_cube_add()
# Get the cube object and rename it.
@openroomxyz
openroomxyz / GenerateUnionOfMultipleObjects.py
Created April 16, 2020 15:05
Blender Python : How do i generate an geometric Union of Multiple Cubes / or others Objects (Union Modifier, efficient way)?
import bpy
import uuid
def create_a_cube(name, position, set_rotation, scale):
# Create a simple cube.
bpy.ops.mesh.primitive_cube_add()
# Get the cube object and rename it.
cube = bpy.context.object
cube.name = name