So, I have a cube and I want to make a game where the cube jumps from a pylon to another and now I am at the point where I want to make the pylon fall if the cube stays on it more than a given amount of time.
I don't want to use physics or rigid body, I am using just transform.position
and Raycast
to click on the next pylon I want the cube to jump, I want to use animations, so if the cub stays more than a given amount of time on the current pylon, that pylon will fall taking the cube with it.
The problem is that I don't know what to do, where to begin; regarding animations in unity I only know how to do Animation Clips.
I would learn to do other things but I actually have no ideea how to approach this problem, what technique should I use to get the desired outcome, and how?
You can use OnCollisionEnter to Detect if the cube has collided with (landed on) the pylon:
void OnCollisionEnter(Collision col)
{
// Check if it is the cube that has collided.
if (col.gameObject.name == "Player") // Make sure to assign the Player Tag to the cube
{
// Start countdown timer.
}
}
You could start a countdown timer using a coroutine.
You will need to add using System.Collections;
at the top of your class.
Call your coroutine using StartCoroutine(MyCoroutine());
IEnumerator MyCoroutine()
{
// Wait for 3 seconds.
yield return new WaitForSeconds(3f);
// Make the pylon fall now.
}
This code will cause the game to wait for 3 seconds before doing something. How you make the pylon fall is up to you, you could use a RigidBody and set isKinematic from true to false as an example, but since you have said you don't want to use physics, you could translate the pylon downwards using Transform.position
.
This should get you started.