connect 3 gameobjects
I have two firemen carrying a ladder, when the ladder comes into contact with a prefab it shrinks or widens. The problem is when it gets smaller, the two firefighters on either side hold it in their position (don't move) and create a gap between the ladder and their hands. I've tried everything, but I don't know how to fix this. When the ladder widens the problem is not there because the colliders of the ladder automatically move the firefighters.
prefab code
Rigidbody2D rb;
float speed;
float altezza;
public float asseX;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
speed = Random.Range(1f, 4f);
altezza = Random.Range(0.5f, 2.9f);
rb.velocity = new Vector2(speed, altezza);
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "barella")
{
Barella.instance.transform.localScale += new Vector3(asseX, 0, 0); // LADDER
// Pompieri.instance.transform.position += new Vector3(asseX, 0, 0); // FIREMAN -- doesn't work
Destroy(gameObject);
}
if (coll.gameObject.tag == "terra")
{
Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
[HELP] Setting the parent of a transform which resides in a prefab is disabled 1 Answer
My gameobject disappears when I transform it 1 Answer
How to get continuous reference to a GameObject's position? 2 Answers
My Enemies start to shoot wrong way.,Help me my enemy's dont shoot at me 0 Answers
cannot drag and assign other class from script to prefab 0 Answers