Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda