Need Help, Working on a 2d game and need to check for tags on two different objects.

if (collision.CompareTag("StatsUp"))
{
    void OnTriggerStay(Collider other)
    {
        if (other.gameObject.Tag == "Player")
        {
            Debug.Log ("Success!");
        }
    }
    StatsUp();
}

this is the base code for my collision script. I can detect the object the player hits but dont know how to get the players tag. (game has two players)
does anyone have suggestions.

sorry if script is unclear this is my first post and 2d project.

Well let’s fix that first.

You have an if statement with a function inside it.

That is legal but makes no sense in a Unity3D context.

Unity cannot “see” methods inside other blocks of code.

Slow down, return to whatever tutorial or guide you are working from and nail it down 100% correct.

If you need to check two separate objects, most likely you need to set a boolean for each one, then have some other mechanism check if both booleans are true / false and do what you want there.

Tutorials for things like “pull several levers to open a single door” might be useful in this context.

Imphenzia: How Did I Learn To Make Games:

https://www.youtube.com/watch?v=b3DOnigmLBY

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Is the script on the Player? If so, couldn’t you just do gameObject.tag?

The script is one every iteration of the player.
This is all scripts relevant.

NOTE not all of this is in use, some was in attempt to add more features
Sorry for any messy code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class GameController : MonoBehaviour
{
   Vector2 startPos;
   private float RespawnPlayer1;
   private float RespawnPlayer2;


   private PlayerMovement player1;
   private PlayerMovement2 player2;


   private void Start()
   {
       startPos = transform.position;
       player1 = GetComponent<PlayerMovement>();
       player2 = GetComponent<PlayerMovement2>();
   }

   void Update()
   {
       //RespawnPlayer1 = input.GetAxisRaw("Fire2");
       if (Input.GetButton("Fire2"))
       {
           Die();
       }

       //RespawnPlayer2 = input.GetAxisRaw("Fire3");
       if (Input.GetButton("Fire3"))
       {
           Die();
       }

   }

   private void OnTriggerEnter2D(Collider2D collision)
   {
        if (collision.CompareTag("Obstical"))
        {
            Die();
        }

        else if (collision.CompareTag("Checkpoint"))
        {
            startPos = transform.position;
        }

        if (collision.CompareTag("Finish"))
        {
            QuitGame();
        }

        /*if (collision.CompareTag("StatsUp"))
        {
            void OnTriggerStay(Collider other)
            {
                if (other.gameObject.Tag == "Player")
                {
                    Debug.Log ("Success!");
                }
            }
            StatsUp();
        }

        if (collision.CompareTag("StatsDown"))
        {
            StatsDown();
        }

        if (collision.CompareTag("StatsReset"))
        {
            StatsReset();
        }*/

   }



   public void QuitGame()
    {
        // save any game data here
        #if UNITY_EDITOR
            // Application.Quit() does not work in the editor so
            // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
            UnityEditor.EditorApplication.isPlaying = false;
        #else
            Application.Quit();
        #endif
    }

   void Die()
   {
       Respawn();
   }

   void Respawn()
   {
       transform.position = startPos;
   }

  
}
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    private float horizontal;
    public float speed = 7f;
    public float jumpingPower = 19f;
    private bool isFacingRight = true;

    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private Transform groundCheck;
    [SerializeField] private LayerMask groundLayer;

    void Update()
    {
        horizontal = Input.GetAxisRaw("Horizontal");

        if (Input.GetButtonDown("Jump") && IsGrounded())
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
        }

        if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
        {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
        }

        Flip();
    }

    private void FixedUpdate()
    {
        rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    }

    private bool IsGrounded()
    {
        return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    }

    private void Flip()
    {
        if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }
    }

    void StatsUp()
    {
        speed = speed + 1;
        jumpingPower = jumpingPower + 1;
    }

    void StatsDown()
    {
        speed = speed - 1;
        jumpingPower = jumpingPower - 1;
    }

    void StatsReset()
    {
        speed = 7f;
        jumpingPower = 19f;
    }
}
using UnityEngine;

public class PlayerMovement2 : MonoBehaviour
{
    private float horizontal;
    public float speed = 7f;
    public float jumpingPower = 19f;
    private bool isFacingRight = true;

    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private Transform groundCheck;
    [SerializeField] private LayerMask groundLayer;

    void Update()
    {
        horizontal = Input.GetAxisRaw("Vertical");

        if (Input.GetButtonDown("Fire1") && IsGrounded())
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
        }

        if (Input.GetButtonUp("Fire1") && rb.velocity.y > 0f)
        {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
        }

        Flip();
    }

    private void FixedUpdate()
    {
        rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    }

    private bool IsGrounded()
    {
        return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    }

    private void Flip()
    {
        if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }
    }

    void StatsUp2()
    {
        speed = speed + 1;
        jumpingPower = jumpingPower + 1;
    }

    void StatsDown2()
    {
        speed = speed - 1;
        jumpingPower = jumpingPower - 1;
    }

    void StatsReset2()
    {
        speed = 7f;
        jumpingPower = 19f;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelChangeScript : MonoBehaviour
{

    public int sceneBuildingIndex;

    void start()
    {
        SceneManager.UnloadScene(sceneBuildingIndex);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {


        print("trigger Entered");

        if(other.tag == "Player")
        {
            print("Switching Scene to " + sceneBuildingIndex);
            SceneManager.LoadScene(sceneBuildingIndex, LoadSceneMode.Single);
        }
        else if(other.tag == "PlayerB")
        {
            print("Switching Scene to " + sceneBuildingIndex);
            SceneManager.LoadScene(sceneBuildingIndex, LoadSceneMode.Single);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PatrolMovement : MonoBehaviour
{
    public float speed;
    Vector3 targetPos;

    public GameObject Ways;
    public Transform[] wayPoints;
    int pointIndex;
    int pointCount;
    int direction = 1;

    private void Awake()
    {
        wayPoints = new Transform[Ways.transform.childCount];
        for (int i = 0; i < Ways.gameObject.transform.childCount; i++)
        {
            wayPoints[i] =Ways.transform.GetChild(i).gameObject.transform;
        }
    }

    private void Start()
    {
        pointCount = wayPoints.Length;
        pointIndex = 1;
        targetPos = wayPoints[pointIndex].transform.position;
    }

    private void Update()
    {
        var step = speed * Time.deltaTime;
        transform.position = Vector3.MoveTowards(transform.position, targetPos, step);

        if (transform.position == targetPos)
        {
            NextPoint();
        }
    }

    void NextPoint()
    {
        if (pointIndex == pointCount -1)
        {
            direction = -1;
        }

        if (pointIndex == 0)
        {
            direction = 1;
        }

        pointIndex += direction;
        targetPos = wayPoints[pointIndex].transform.position;
    }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CompleteLevel : MonoBehaviour
{
    public float speed;
    Vector3 targetPos;

    public GameObject Ways;
    public Transform[] wayPoints;
    int pointIndex;
    int pointCount;
    int direction = 1;
    public int Complete;

    public CompleteLevel()
    {
        Complete = 0
    }

    private void Awake()
    {
        wayPoints = new Transform[Ways.transform.childCount];
        for (int i = 0; i < Ways.gameObject.transform.childCount; i++)
        {
            wayPoints[i] =Ways.transform.GetChild(i).gameObject.transform;
        }
    }

    private void Start()
    {
        pointCount = wayPoints.Length;
        pointIndex = 1;
        targetPos = wayPoints[pointIndex].transform.position;
        Complete = 0;
    }

    private void Update()
    {
        var step = speed * Time.deltaTime;
        transform.position = Vector3.MoveTowards(transform.position, targetPos, step);

        if (transform.position == targetPos)
        {
            if (Complete = 1)
            {
                NextPoint();
            }
           
        }
    }

    void NextPoint()
    {
        if (pointIndex == pointCount -1)
        {
            direction = -1;
        }

        if (pointIndex == 0)
        {
            direction = 1;
        }

        pointIndex += direction;
        targetPos = wayPoints[pointIndex].transform.position;
    }

Here is an Asset Clone of the project incase code is unclear.

9826968–1412808–2DGameClone-May10.unitypackage (5.36 MB)