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

Help Making a Mirror

Discussion in 'Scripting' started by CapitalistSquid, Sep 3, 2016.

  1. CapitalistSquid

    CapitalistSquid

    Joined:
    Aug 30, 2015
    Posts:
    12
    Hello,
    I am attempting to make a mirror as a part of my game. My thought process was to instantiate the player, rotate them 180 degrees and put them on the opposite side of the mirror. Here is the code that I have:
    Code (CSharp):
    1. void OnTriggerEnter(Collider other, Transform oth)
    2.     {
    3.         if (other.tag == "Mirror")
    4.         {
    5.             newpos = new Vector3(2 * oth.position.x - transform.position.x, transform.position.y, 2 * oth.position.z - transform.position.z);
    6.             newrot = new Quaternion(transform.rotation.x + 180, transform.rotation.y, transform.rotation.z, transform.rotation.w);
    7.             Instantiate(dupePrefab, newpos, newrot);
    8.             Debug.Log("here");
    9.         }
    10.     }
    Currently I am recieving this error:
    Code (CSharp):
    1. Script error: OnTriggerEnter
    2. The message must have 0 or 1 parameters.
    3. The message will be ignored.
    4.  
    Why is this happening? Is there some way to fix this?

    Thank you.
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    You gave the method 2 parameters...It says you need 0 or 1. @AcidArrow linked you the proper way of declaring OnTriggerEnter.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    But somebody should point out that this probably isn't the best way to make a mirror. You may want instead to use a RenderTexture. Do a google search for "unity mirror" and you'll find a lot of resources about it.
     
  5. CapitalistSquid

    CapitalistSquid

    Joined:
    Aug 30, 2015
    Posts:
    12
    Is there any way to use both parameters because I need to record the position of the collider to calculate where the newly instantiated object will form?
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Your collider parameter already contains that info.
    So other.transform.position should work just fine.