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

Update() OnCollisionEnter

Discussion in 'Scripting' started by Vindatra14, Nov 17, 2015.

  1. Vindatra14

    Vindatra14

    Joined:
    May 8, 2015
    Posts:
    87
    Code (CSharp):
    1. void Update (){
    2.         OnCollisionEnter2D (Collision2D coll)
    3.         {
    4.             alpha = alphacolor.GetComponent<SpriteRenderer> ();
    5.             Color opa = alpha.color;
    6.            
    7.             if (coll.gameObject.name == "Bin") {
    8.                 opa.a = 0.5f;
    9.                 alpha.color = opa;
    10.             }
    11.         }
    How to write like this ?? I get error when I write it like this, any help will be appreciate and thanks :D
     
    saikowshik82 likes this.
  2. aLovedHater

    aLovedHater

    Joined:
    Oct 12, 2014
    Posts:
    16
    OnCollisionEnter is a method itself, so you can't put it in the method "Update()"

    look here for more info:http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter2D.html

    PS - Unity's scripting API goes into detail on many things that you may need answered, often googling it will find you a faster answer to your question rather than asking it on the forums and having to wait =)
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    If this is the level of experience you have then it's clear you don't understand programming at all, and should spend at least 2 weeks with a good C# instruction book to warm up... or you'll keep trying to pilot a space shuttle (which is burning up in orbit) using a piece of celery in a plug socket.
     
  4. Vindatra14

    Vindatra14

    Joined:
    May 8, 2015
    Posts:
    87
    I know it a little about it, what I want to ask is how I can check mouseUp onCollisionEnter. Bcoz I know the mouseUp only can check at update coz it update and check it every frame. Then I need to know how to check the mouseUp onCollisionEnter