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
NAME : SWATHIKA G
REG NO : 212221230113
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Object1 : MonoBehaviour
{
// Start is called before the first frame update
public float xmove = 7.0f;
public float zmove = 5.0f;
public float ymove = 150.0f;
void Start()
{
}
// Update is called once per frame
void Update()
{
float x = 0.0f;
if(Input.GetKey(KeyCode.UpArrow))
{
x += xmove;
}
if(Input.GetKey(KeyCode.DownArrow))
{
x -= xmove;
}
float z = 0.0f;
if(Input.GetKey(KeyCode.RightArrow))
{
z -= zmove;
}
if(Input.GetKey(KeyCode.LeftArrow))
{
z += zmove;
}
float y = 0.0f;
if(Input.GetKeyDown(KeyCode.Space))
{
y = ymove;
}
GetComponent<Rigidbody>().AddForce(x, y, z);
}
}
Thus, The 3D application for Roll the Ball objects in unity is developed successfully.