0% found this document useful (0 votes)
34 views6 pages

Ball Game

The document provides instructions for setting up a ball game in Unity: 1. It instructs the user to create folders to organize project assets and an initial platform object. 2. Materials are added to the platform and ball, and a rigidbody component is added to the ball to apply physics. 3. A BallController script is created and attached to the ball to control its movement, detecting input and collisions.

Uploaded by

David Ist
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

Ball Game

The document provides instructions for setting up a ball game in Unity: 1. It instructs the user to create folders to organize project assets and an initial platform object. 2. Materials are added to the platform and ball, and a rigidbody component is added to the ball to apply physics. 3. A BallController script is created and attached to the ball to control its movement, detecting input and collisions.

Uploaded by

David Ist
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Ball Game

Layout 2 by 3
1
Free aspect 480 X 800
2Creare foldere Scripts, Scenes, Material, PhysicsMaterials
File – Save as – Scenes – level1
3 Hierarchy -Create – 3d Object –Cube (Rename –PlatformStart)
Inspector – Transform –Reset
Scale X=10 Z=10
4Hierarchy- Create – 3d Object – Sphere (Rename – Ball)
Click Ball + F – Zoom pe obiect
5 Folderul Material – Create –Material –Blue(color)
Setare culoare Albedo
Drag &Drop - Blue (Material) –PlatformStart
Folderul Material – Create –Material –Black(color)
Setare culoare Albedo
Drag &Drop - Black (Material) –Ball
6
Ball – INSPECTOR – Add component – Physics – Rigidbody
Debifam Use Gravity
Angular Drag – 0
Constrains – Freeze Position (Y)
-Freeze Rotation (X,Y,Z)
!!!SAVE
7 Folder Scripts – Create – C# Scripts – BallController
Ball – Add Component – BallController

8 Select MainCamera – Game Object –Align with View

9 Folder PhysicsMaterials – Create – Physics Material (ZeroFriction)


Dynamic Friction -0
Static Friction – 0
Ball – Sphere Collider –Material –Drag&Drop (ZeroFriction-PhysicsMaterials)
10 PlatformStart – Box Collider –Material –Drag&Drop (ZeroFriction)

11 Click dreapta –PlatformStart –


Duplicate (Rename –Platform – modifica Scale)
void Update()
using System.Collections; {
using System.Collections.Generic; if (!started)
{
using UnityEngine;
if (Input.GetMouseButtonDown(0))
{
public class BallController : MonoBehaviour rb.velocity = new Vector3(speed, 0, 0);
{ started = true;
}
}
[SerializeField] if (!Physics.Raycast(transform.position, Vector3.down, 1f))
private float speed; {
bool started; gameOver = true;
rb.velocity = new Vector3(0, -25f, 0);
bool gameOver;
}
if (Input.GetMouseButtonDown(0) && !gameOver)
Rigidbody rb; {
SwitchDirection();
}
}
private void Awake() void SwitchDirection()
{ {
rb = GetComponent<Rigidbody>(); if (rb.velocity.z > 0)
{
}
rb.velocity = new Vector3(speed, 0, 0);
// Start is called before the first frame update }
void Start() else if (rb.velocity.x > 0)
{ {
rb.velocity = new Vector3(0, 0, speed);
started = false;
}
gameOver = false; }
} }

You might also like