Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I target one script specifically when its instantiated twice at run time.

Discussion in 'Scripting' started by TheIrishPizzaGuy, Jun 18, 2019.

  1. TheIrishPizzaGuy

    TheIrishPizzaGuy

    Joined:
    Jun 18, 2019
    Posts:
    6
    Code (CSharp):
    1.             if (Player.theCurScale == 1)
    2.             {
    3.                 transform.rotation = Quaternion.identity;
    4.             }
    5.             else
    6.             {
    7.                 transform.rotation = Quaternion.Euler(0f, 180f, 0f);
    8.             }
    [Solved]I have a 2 player fighting game and am having some problems.
    The players can shoot projectiles (another script) from them, but it is linked to the a static variable that shows which direction they are facing (int face right //1 = right, -1 = left).
    This works perfectly fine with only one player. But when I duplicated the player and changed the key binds and such, they read each others variables. So if player 1 is facing left, and player 2 is facing, the shot from both players shoots right.
    Is there any way to specify an instance of the script during run time

    I know this has to be a simple fix and it is my first time posting, forgive my ignorance :)
     
    Last edited: Jun 18, 2019
  2. TheIrishPizzaGuy

    TheIrishPizzaGuy

    Joined:
    Jun 18, 2019
    Posts:
    6
    if (playerOne)
    player = GameObject.Find("Player").GetComponent<PlayerScript>();
    else
    player = GameObject.Find("Player (2)").GetComponent<PlayerScript>();