Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!