Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

I ran into a problem with my scipt

A topic by GreenViper2020 created Feb 26, 2022 Views: 254 Replies: 7
Viewing posts 1 to 8
Submitted (1 edit)

Hey I wanted to detect if my player is colliding with my game object. It works in my first scene but it doesnt in my second.  I don't get the dubug.log "awsner" and my panal doesnt activate. Do you know any reasons for this problem?

Here is the Code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;

using UnityEngine.UI;

public class NextLevelCollision1 : MonoBehaviour

{

    

    public GameObject NextLevelPanal;

    // Start is called before the first frame update

    void Awake()

    {

        NextLevelPanal.SetActive(false);

    }

    // Update is called once per frame

    void Update()

    {

        

    }

    public void OnTriggerEnter(Collider collider)

    {

        if(collider.gameObject == CompareTag("NextLevel"))

        {

            NextLevelPanal.SetActive(true);

            Debug.Log("PANALACTIVE");

            Cursor.lockState = CursorLockMode.Confined;

        }

    }

}

Submitted

Try with the "OnColliderEnter" instead or you have not set the collider to trigger in the second scene.

Submitted

Thanks but it sadly didn't worked. I used a charakter controlller which is build in in unity. Could this be the problem?

Submitted
Deleted 200 days ago
Submitted

Thanks but it sadly didn't worked. I used a charakter controlller which is build in in unity. Could this be the problem?

Submitted

could you show us a screenshot of the player and the other gameobject's inspector? 

Submitted(+1)

Try using other.tag == “”

public void OnTriggerEnter(Collider collider) { if (collider.tag == “Your_Tag_Here”){ Debug.Log (“Collider”); } }

(+1)

try    if(collider.gameObject.tag == "NextLevel") or    if(collider.tag == "NextLevel") please reply if it works

(+1)

try checking the "is trigger" check mark in the collider of the gameobject or the player