Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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