-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.cs
More file actions
44 lines (37 loc) · 1.16 KB
/
Ball.cs
File metadata and controls
44 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Ball : MonoBehaviour {
public bool ballLaunched = false;
private Rigidbody rigidBody;
private AudioSource audioSource;
private float ballPosX;
private float ballPosZ;
private Vector3 ballStartPosition;
private Text leftPanelText;
// Use this for initialization
void Start () {
rigidBody = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
rigidBody.useGravity = false;
ballStartPosition = transform.position;
leftPanelText = GameObject.Find("UI Canvas").GetComponentInChildren<Text>();
}
public void Launch(Vector3 velocity){
ballLaunched = true;
rigidBody.useGravity = true;
rigidBody.velocity = new Vector3(velocity.x, velocity.y, velocity.z + 200f);
audioSource.Play();
}
public void Reset(){
// Resets ball after pins have settled
leftPanelText.color = new Color(27, 0, 227);
transform.position = ballStartPosition;
transform.rotation = Quaternion.identity;
rigidBody.useGravity = false;
ballLaunched = false;
rigidBody.velocity = Vector3.zero;
rigidBody.angularVelocity = Vector3.zero;
}
}