Professional Documents
Culture Documents
RollBall Practical 7
RollBall Practical 7
Steps:
After logging in : Select 3D template Give project name click on create project
Plus Symbol below Hierarchy ->Select 3D Object ->Select Plane -> inside inspector window -> give
name: Ground
Plus Symbol below Hierarchy ->Select 3D Object ->Select Sphere -> inside inspector window -> give
name: Player -> Position -> change Y value to 0.5 (now the sphere is completely visible)
Click on plus sign below the Project Window -> select Folder -> give name: materials
Keep the materials folder selected -> again click on plus sign below the Project Window -> select
Material -> give name: background
Inspector window of background -> Main Maps -> Albedo -> select colour of your choice
Then drag the background to the hierarchy -> on the Ground (you can see the colour changes)
Select Player -> Add component -> New Script -> give name: PlayerController -> open the script and
write code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
}
}
Select Main Camera -> Inspector window -> and change values
Select Main Camera -> Inspector window -> New Script -> give name: CameraController -> open the
script and write code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Select CameraController -> in Inspector window -> drag the Player from hierarchy inside the
Camera Controller Script
Test the game (You can see the camera focus moving along)
Click on plus sign below the Hierarchy -> Create Empty -> rename: Walls
Click on plus sign below the Hierarchy -> 3D Object -> Cube -> rename: westwall
Drag westwall inside Walls and change values for westwall
northwall:
southwall:
Test the game
Click on plus sign below the Project Window -> select Folder -> give name: prefabs
Plus Symbol below Hierarchy ->Select 3D Object ->Select Cube -> inside inspector window ->
give name: Pickup
GameObject Tab -> rename: Pickups
Drag pickup inside pickups
Now drag pickup to prefabs folder
(uncheck Player) Go to Inspector window of Pickup -> change values
Add component -> New Script -> name: Rotator and write code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
}
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}
}
Save and Test
Go to Scene -> change from Local to Global
Make duplicates of Pickup ( Control + D )
Scene Mode -> Change the direction to top view -> Drag and Drop all the Pickups from hieracrchy
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count : " + count.ToString();
if (count >= 9)
{
winText.text = "You win!";
}
}
}
Prefabs folder -> Select Pickup (so it will be updated for all pickups) -> Add component -> Physics
-> Rigidbody (check ‘Is Trigger’ & ‘Is Kinematic’)
Scroll Up -> Click on Tag -> Add Tag -> click on pluss sign -> Name: “PickUp” (this name should
be same as the name inside the code of PlayerController Script -> inside OnTriggerEnter) -> Save
Now again Click on Tag -> you can see PickUp option -> Select PickUp
Click on plus sign below Hierarchy -> UI -> text
Canvas is created -> inside it there is Text -> Rename the text to countText
Select Player -> Then drag the counText from hierarchy to inspector of Player -> PlayerController
Script -> inside CountText
Similarly take one more UI -> name: winText (follow the same steps as for countText)
To add Colors -> Inside materials folder -> create duplicate of background -> give name pickup
-> change color through Albedo (green) -> drag this on to each player
Similarly create duplicate -> rename: player -> change color through Albedo (red) -> drag this on
to player