To Roll a Ball using C# program in unity .
-
File -> Scene -> Select the scene -> Save as-> New folder(Scenes)-> File name (MiniGame)
-
Heirarchy -> 3D Object-> Plane [ Right side-> Inspector-> Change the name of plane (Name: Ground) Transform -> Reset Edit -> FrameSelected ]
-
Scale the ground by giving the scaling value as x=4 y=1 z=4
-
Heirarchy -> 3D Object-> Sphere [ Right side-> Inspector-> Change the name of plane (Name: Player) Transform -> Reset Edit -> FrameSelected Transform -> Position -> y=0.5]
-
Hierarchy -> DirectionalLight [ Inspector -> Change the color to white (255,255,255)]
-
Create a folder in project and name as Materials [Material folder -> Create -> Material (Name: Background) Inspector ->Surface Inputs ->BaseMAp (Choose the color) Metallic map-> 0 Smoothness -> 0.25 Drag the Background to the plane and release the mouse
Material folder -> Create -> Material (Name: Sphere) Inspector ->Surface Inputs ->BaseMAp (Choose the color) Metallic map-> 0 Smoothness -> 0.75 Drag the Sphere material to the ball and release the mouse
-
Hierarchy -> Player-> Inspector ->Add component-> Rigidbody
-
Create a new script -> Create a folder in project (Name: Scripts) Hierarchy -> Player -> Inspector-> AddComponent-> NewScripts-> PlayerController( Click create and Add) Copy the PlayerController and drag to Script folder Double click the PlayerController file and type the coding
### Developed by: Srijith R
### Register Number: 212221240054
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public float XForce = 5.0f;
public float ZForce = 5.0f;
public float YForce = 200f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float x = 0.0f;
if(Input.GetKey(KeyCode.A))
{
x = x - XForce;
}
if (Input.GetKey(KeyCode.D))
{
x = x - XForce;
}
float z=0.0f;
if (Input.GetKey(KeyCode.W))
{
z= z +ZForce;
}
if (Input.GetKey(KeyCode.S))
{
z = z - ZForce;
}
float y= 0.0f;
if (Input.GetKeyDown(KeyCode.Space))
{
y = YForce;
}
GetComponent<Rigidbody>().AddForce(x, y, z);
}
}
Thus, The 3D application for Roll the Ball objects in unity is developed successfully.