Question by
dragonero94 · Apr 20, 2020 at 03:29 PM ·
getcomponentreturn valueimpact
GetComponen doesn't work
Hi, I'm trying to access to impact force located in OnCollisionStay from the main Script that has an array of gameobject. Each one has that same script where are the value of contact force of each gameobject. When I use getcomponent it returns zero for every game object even if there is an impact. Indeed if I debug the force from OnCollisionStay the force is not zero. This is the collisionScript
//Collision script
void OnCollisionStay(Collision col)
{
force = col.impulse.magnitude / Time.fixedDeltaTime;
}
this is the main Script
//main script
float[,] force;
GameObject [,] Tiles;
void Start() {
Tiles[i,j].AddComponent<CollisionScript>();
}
void Update() {
force[i, j] = Tiles[i, j].GetComponent<CollisionScript>();
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612231957im_/https://answers.unity.com/themes/thub/images/avi.jpg)