- Home /
Question by
RobotReebot · Jun 19, 2015 at 08:01 AM ·
collisionprefabbug-perhaps
Problem with a prefab, need help
Hi.
I am making a videogame in 2D that is in the space. I wanted to give some cool effects to the spaceship, so i put under them an afterburner.
I want that when they hit a black hole their size will fall off, but iget the bug on video. How can i solve it?
The video click me
This is the script on hit with "Buco Nero" And it's attached to the player (Dark hole)
using UnityEngine;
using System.Collections;
public class ContattoConBucoNero : MonoBehaviour {
float perditamassa;
int stack;
float time;
GameObject afterburner;
// Use this for initialization
void Start () {
GetComponent<Transform> ().localScale = new Vector3 (2.631793f, 2.631793f, 0.3427396f);
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D myCollider){
if (myCollider.gameObject.tag == "Buconero") {
afterburner=this.transform.GetChild(1).gameObject;
perditamassa=FindClosestBucoNero().GetComponent<CreazioneBucoNero>().stack*0.15f;
stack= FindClosestBucoNero().GetComponent<CreazioneBucoNero>().stack;
if(perditamassa<(GetComponent<Transform>().localScale.x-2.631793f)){
GetComponent<Transform>().localScale= new Vector3(GetComponent<Transform>().localScale.x-perditamassa,GetComponent<Transform>().localScale.x-perditamassa);
GameObject.Find("Main Camera").GetComponent<Camera>().orthographicSize=GameObject.Find("Main Camera").GetComponent<Camera>().orthographicSize-(0.3f*stack);
while (time<=2f) {
time+=Time.deltaTime;
afterburner.GetComponent<ParticleSystem>().startSize= GetComponentInChildren<ParticleSystem>().startSize-(0.76f*(2/stack));
}
}
else{
Debug.LogWarning("Game Over");
}
Destroy(FindClosestBucoNero());
}
}
GameObject FindClosestBucoNero() {
GameObject[] gos;
gos = GameObject.FindGameObjectsWithTag("Buconero");
GameObject closest = null;
float distance = Mathf.Infinity;
Vector3 position = transform.position;
foreach (GameObject go in gos) {
Vector3 diff = go.transform.position - position;
float curDistance = diff.sqrMagnitude;
if (curDistance < distance) {
closest = go;
distance = curDistance;
}
}
return closest;
}
}
Thanks for all the help
Comment
Your answer
Follow this Question
Related Questions
Can prefabs interact with scroll rect? 0 Answers
Destroy a specific prefab (GameObject) Unity2D 1 Answer
Tagged collision problem 1 Answer
Ignoring collisions without using physics layers 1 Answer
Odd behaviour when instatiated 1 Answer