Is there an easy way of refilling the fuel gauge in my truck game. Based on Colliding with certain objects.
Could I please have some help with the coding of this.
Is there an easy way of refilling the fuel gauge in my truck game. Based on Colliding with certain objects.
Could I please have some help with the coding of this.
Sounds like you want OnCollisionEnter, it will get called when you collide with an object, you can then test what the object is and decide what to do.
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
Thank you very much for your help. I know how to do the coding for the OnCollisionEnter. I am not sure how to do the coding for making the truck refuel based on the object collision. Could I please have some help with that?
Its hard to say without knowing how the rest of your code looks.
An assumption would be something like this
Assuming the script is on the fuel object
....
public float fuel = 10;
void OnCollisionEnter(Collision collision)
{
TruckFuelSupply tf = collision.collider.GetComponent<TruckFuelSupply>();
tf.currentFuel += fuel;
}
...
This script would allow objects to give various amounts of fuel to the truck based on the fuel variable
Karl