-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGlassPieces.cs
More file actions
34 lines (30 loc) · 1.02 KB
/
GlassPieces.cs
File metadata and controls
34 lines (30 loc) · 1.02 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GlassPieces : MonoBehaviour {
public int noOfPieces = 10;
// public Vector2 force;
public GameObject piece;
// public float radius = 2f;
bool hit;
void OnCollisionEnter(Collision other)
{
if(other.collider.tag == "Ball" && !hit)
{
this.gameObject.tag = "Untagged";
hit = true;
// this.GetComponent<Collider>().enabled = false;
for (int i = 0; i < noOfPieces; i++)
{
GameObject glasspiece = Instantiate(piece, other.transform.position, Quaternion.identity);
glasspiece.transform.localScale = new Vector3(transform.localScale.x/2, transform.localScale.y/2,
transform.localScale.z/2);
// Destroy(pieceRb.GetComponent<GlassPieces>());
// pieceRb.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
// float randForce = Random.Range(force.x,force.y);
// pieceRb.AddExplosionForce(randForce, Vector3.up, radius);
}
Destroy(this.gameObject);
}
}
}