Hi, guys i’m starting to make games with unity so i’m looking some tutorials to learn, i just draw a player,and when him die the body parts sometimes are the same parts i want to changed it to only take 1 part no clone the part, because they are 5 parts when explote here the script… PD: sorry for my english… btw somebody can post here tutos to learn C# would be good thanks.
:using UnityEngine;
using System.Collections;
public class Explode : MonoBehaviour {
public BodyPart bodyPart;
public int totalParts = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D target){
if (target.gameObject.tag == "Deadly") {
OnExplode();
}
}
void OnExplode(){
Destroy (gameObject);
var t = transform;
for (int i = 0; i < totalParts; i++) {
t.TransformPoint(0, -100, 0);
BodyPart clone = Instantiate(bodyPart, t.position, Quaternion.identity) as BodyPart;
clone.rigidbody2D.AddForce(Vector3.right * Random.Range(-50, 50));
clone.rigidbody2D.AddForce(Vector3.up * Random.Range(100, 400));
}
}
}
THANKS.