Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
Unable to disable a collider

I am doing a dig the mud game. Have 2 mud gameobject(sprite) that need to dig in the correct order. I assign one script for each object. Disable mud2 boxcollider to prevent them from moving until mud 1 is drag to trigger L box collider . But when I try playing, mud2 still can be drag even though mud1 havent trigger L box collider. I also untick the box collider of mud2.

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

public class pg7_mud1 : MonoBehaviour
{
   private Vector3 screenPoint;
   private Vector3 startPosition;

   public BoxCollider mud2;
   // Start is called before the first frame update
   void Start()
   {
       mud2.enabled = false;
   }

   // Update is called once per frame
   void Update()
   {
    
    
   }

    void OnMouseDown()
   {
      
       startPosition = this.gameObject.transform.position;
       screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
       
   }

   void OnMouseDrag()
   {
      Debug.Log("can drag");
       Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
       Vector3 curPosition = Camera.main.ScreenToWorldPoint (curScreenPoint);
       this.transform.position = new Vector3(curPosition.x, -5f, curPosition.z);  
   }

    void OnTriggerEnter(Collider other)
   {
       if(other.gameObject.name =="left-area")
       {   
           Debug.Log("touched edge");
           mud2.enabled = true;
       }
   }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You could try the Destroy(object, time) method instead of disabling colliders

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

public class pg7_mud1 : MonoBehaviour
{
   private Vector3 screenPoint;
   private Vector3 startPosition;

   public BoxCollider mud2;
   public gameObject mud2obj;
   // Start is called before the first frame update
   void Start()
   {
       destroy(mud2);
   }

   // Update is called once per frame
   void Update()
   {
    
    
   }

    void OnMouseDown()
   {
      
       startPosition = this.gameObject.transform.position;
       screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
       
   }

   void OnMouseDrag()
   {
      Debug.Log("can drag");
       Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
       Vector3 curPosition = Camera.main.ScreenToWorldPoint (curScreenPoint);
       this.transform.position = new Vector3(curPosition.x, -5f, curPosition.z);  
   }

    void OnTriggerEnter(Collider other)
   {
       if(other.gameObject.name =="left-area")
       {   
           Debug.Log("touched edge");
           mud2obj.AddComponent(typeof(BoxCollider));
       }
   }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda