Making things happen upon collision

Ok so I just started using unity about 2 days ago and I’m looking for some advice when coding. I’m using c# and basically what im trying to make happen is when the player touches a platform I want it to play an audio file and raise a cube a certain distance. I don’t really know anything about coding and help would be appreciated

Basically you want to respond to OnCollisionEnter. More details is… a long story.

start writing out your algorithm in pseudo-code. Then you just need to figure out the exact code. it is pretty easy to google the C# code when you can break it out into small enough chunks.

so for your example:

When [trigger] happens:
{
       play audiosource
       move platform's transform position
}

so you need to learn 3 separate things

  • how colliders trigger actions (function mentioned above)
  • how to play an audio source via a script
  • how to move an object via a script.

I’ll add that the the official tutorials go over a lot of these basic concepts. you may save some time and frustration by going through the first 3 of them at a minimum. the tutorials cover both coding basics and how to use the unity interface.

1 Like

incidentally does

mean you are new to programming entirely or only that you are unfamiliar with how programming works within Unity? If you mean the latter, you should checkout my book Unity in Action.

My advice is to stop doing what you want to do and start making any chosen tutorial series in Unity Learn section(like Roll-a-ball). Then go back to your ideas.

1 Like