Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Making things happen upon collision

Discussion in 'Getting Started' started by Pintobag, Jul 27, 2015.

  1. Pintobag

    Pintobag

    Joined:
    Jul 27, 2015
    Posts:
    1
    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
     
  2. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    813
    Basically you want to respond to OnCollisionEnter. More details is... a long story.
     
  3. james_m_russell

    james_m_russell

    Joined:
    Jun 2, 2015
    Posts:
    25
    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:

    Code (csharp):
    1.  
    2. When [trigger] happens:
    3. {
    4.        play audiosource
    5.        move platform's transform position
    6. }
    7.  
    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.
     
    Schneider21 likes this.
  4. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    813
    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.
     
  5. Ness

    Ness

    Joined:
    Oct 1, 2012
    Posts:
    182
    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.
     
    tedthebug likes this.