Move, Zoom and Rotate Camera – Unity3D (C#) Move: It is same as moving character. Just use keyboard buttons and move camera with a float speed variable. private float speed = 2.0f; void Update () { if (Input.GetKey(KeyCode.RightArrow)){ transform.position += Vector3.right * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.LeftArrow)){ transform.position += […]
Unity3D
Add Sound Effect – Unity3D (C#) You can add sound effects for all actions in your project. For example, when your character jumps or collides another object or just click on a button, you can call your sound effect. At first, add an “Audio Source” to your scene. As you […]
Add Sound Effect – Unity3D (C#)
Tile-Based Ground – Unity3D (C#) To create a tile-based ground, we need a simple matrix system. A (row X column) matrix will take a plane texture and draw it in each cell. public GameObject plane; public int width = 10; public int height = 10; private GameObject[,] gridd = […]
Tile-Based Ground – Unity3D (C#)
Grid System – Unity3D (C#) Grid system is used mostly in RTS games. Your characters or buildings move on grids. You need a matrix to create a grid system. public float cell_size = 2.0f; private float x, y, z; void Start() { x = 0f; y = 0f; z = 0f; […]
Grid System – Unity3D (C#)
Mouse Click on Game Object – Unity3D (C#) There are two ways to perform click function on a game object: 1- Create and attach a script to the target object. Write this function in it. void OnMouseDown(){ Destroy(gameObject); } 2- You can use Physics.Raycast to detect target with ray. […]
Mouse Click on Game Object – Unity3D (C#)
Destroy Object by Hit – Unity3D (C#) Before implement this code, please check if you add “Rigidbody” component to your objects and “Is Trigger” box is selected. Otherwise, it doesn’t work. 1 2 3 4 5 void OnTriggerEnter(Collider c){ if (c.collider.tag == "Enemy") { Destroy(c.gameObject); } } void OnTriggerEnter(Collider c){ […]
Destroy Object by Hit – Unity3D (C#)
Add Terrain and Skybox – Unity3D You can add terrain in Hierarchy window by clicking on Create button. But first, add a “directional light” in your scene to see your 3D objects clearly in your game scene. Click on terrain and its specifications appear on Inspector. There are 7 buttons […]
Add Terrain and Skybox – Unity3D
Character Control with Keyboard – Unity3D (C#) I will show you 2 ways to move your character with keyboard. Create a cube named “Char” and create a script named “Movement”. You can attach this script to Char object but we won’t. Lets create an object before Start() function: public GameObject character; […]
Character Control with Keyboard – Unity3D (C#)
“Hello World” for Dummies… – Unity3D When you open Unity 3D, you will see a window like this. Under the “Hierarchy” title, a main camera is created as default and you can create your objects in here and see it in “Scene” window. In Scene window, you can move, rotate […]
