Professional Documents
Culture Documents
1. Aim/Overview of the practical: Moving, rotating & scaling Game objects and in Unity and
Add colors, textures, and Parent and child to the Game object.
ii) Vs Code
PROCEDURE:
1. Create a new project.
Fig. 1. Create a new project.
First, you have to open the Unity project. Create the Plane for your game.
Click on the "GameObject" menu in the menu bar. Select 3D objects and pick the "Plane" option.
Fig. 2. Adding 3D Object Plane.
Click on the "GameObject" menu in the menu bar. Select 3D objects and pick the "Cube" option.
Fig. 3. Adding 3D Object Cube.
We create material assets of two different colors and add it to the objects.
Fig. 3. Adding material to the objects.
3. Create C# Script.
A. (Jump,Horizontal,Vertical)
using System.Collections; using
System.Collections.Generic; using
UnityEngine;
Vector3 Vec;
// Start is called before the first frame update
void Start()
Vec = transform.localPosition;
}
Go back to the Unity window. Drag and drop the move script onto the cube.
Press "Up Arrow" Key, and the Cube will move in a forward direction.
Fig. 5. Up arrow movement
Press the "Down Arrow" Key, and the Cube will move in a backwards direction.
Press the "Left Arrow" Key, and the Cube will move to the left.
Fig. 7. Left arrow movement.
Press the "Right Arrow" Key, and the Cube will move to the right.
using UnityEngine;
{ if (Input.GetKey(KeyCode.UpArrow))
{ this.transform.Translate(Vector3.forward * Time.deltaTime);
} if (Input.GetKey(KeyCode.DownArrow))
{ this.transform.Translate(Vector3.back * Time.deltaTime);
} if (Input.GetKey(KeyCode.LeftArrow))
{ this.transform.Rotate(Vector3.up, -10);
if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Rotate(Vector3.up, 10);
}
Press "Left & Right Arrow" Key, and the Cube will Rotate to the left and right.
Press the "Up & Down Arrow" Key, and the Cube will move forward and backwards.
Fig. 11. Object moved backward. Fig. 12. Object moved forward.
C. Move the object by using keys W,A,S and D.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
{ if (Input.GetKey(KeyCode.A))
} if (Input.GetKey(KeyCode.D))
} if (Input.GetKey(KeyCode.S))
}
if (Input.GetKey(KeyCode.W))
Press “D” key. The object will move to the right side.
Press the “A” key. The object will move to the left side.
Fig. 16. “A” Key movement.
LEARNING OUTCOMES: