• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change fall delay of a gameobject by time? (C#, Unity)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all: sorry, if this website is not familiar with these kind of questions.

I want my gameobjects to fall faster by time as the player collides with them. What I mean is, when the game starts, the gameobjects fall off after 1 second the player collided with them, but after 60 seconds, gameobjects only fall after 0.3 seconds after the player has been collided with them.
The idea is to give the player less time to jump from a platform (gameobject) to another platform as the time goes, so it will be more challenging.
Here is what I've made so far:


I tried to use "yield return new WaitForSeconds(1f)" inside "FallDelay()" but of course it didn't change the fall delay after time.

Can anyone help me how to fix that?
Helps are appreciated!
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

I'm not super familiar with Unity, but doesn't it have a built-in gravity simulator? You don't have to perform the transformation yourself. I think you just disable gravity for your platforms, and after a certain delay after you've touched the platform, you simply enable gravity for the platform and Unity will work its magic.

With that out of the way, how do you implement the fall delay? You need some sort of container that holds the current delay and that is accessible from your platforms. To do this, you can create a ScriptableObject class in your Assets directory that encapsulates your game state:

In your inspector, create an instance of this asset from the right-click menu. You should be able to set initial values for the various properties of your new game object.

You can then use this game object from your platform behavior:

So how and when do you call the DecreaseDelay() method? I recommend adding another object to your scene and adding a component to your object that periodically decreases the fall delay:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic