question

renald657-0383 avatar image
0 Votes"
renald657-0383 asked JackJJun-MSFT commented

A HELP in Unity C# code:

hi there, This below code works absolutely fine : the DRAG AND DROP function works good. Here when correct image is droped on to its correct place it stays , but how to lock the image once its dropped in its correct position?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
    
 public class manager1 : MonoBehaviour 
    
 {
     
    public GameObject gorilla, dog, rabbit, lion, goat, gorillaBlack, dogBlack, rabbitBlack, lionBlack, goatBlack;
    
     Vector3 gorillaInitialPos, dogInitialPos, rabbitInitialPos, lionInitialPos, goatInitialPos;
    
     void Start()
    
    
    
     {
        gorillaInitialPos=gorilla.transform.position;
        dogInitialPos=dog.transform.position;
        rabbitInitialPos=rabbit.transform.position;
        lionInitialPos=lion.transform.position;
        goatInitialPos=goat.transform.position;
    
     }
    
    
    
 //1
     public void Draggorilla()
     {  
         gorilla.transform.position = Input.mousePosition;
             
     }
    
    
 //2
     public void Dragdog()
     {  
         dog.transform.position = Input.mousePosition;
     }
    
    
 //3
     public void Dragrabbit()
     {  
         rabbit.transform.position = Input.mousePosition;
     }
    
    
 //4
     public void Draglion()
     {  
         lion.transform.position = Input.mousePosition;
     }
    
    
 //5
     public void Draggoat()
     {  
         goat.transform.position = Input.mousePosition;
     }
    
    
    
    
    
 //1
    
 public void Dropgorilla()
     {
    
         float Distance = Vector3.Distance(gorilla.transform.position, gorillaBlack.transform.position);
         if (Distance < 50)
            
         {
             gorilla.transform.position = gorillaBlack.transform.position;
                 
         }
         else
         {
             gorilla.transform.position = gorillaInitialPos;
         
         }
    
     }
 //2
    
         public void Dropdog()
     {
    
         float Distance = Vector3.Distance(dog.transform.position, dogBlack.transform.position);
         if (Distance < 50)
         {
             dog.transform.position = dogBlack.transform.position;
                 
         }
         else
         {
             dog.transform.position = dogInitialPos;
         
         }
    
     }
 //3
    
 public void Droprabbit()
     {
    
         float Distance = Vector3.Distance(rabbit.transform.position, rabbitBlack.transform.position);
         if (Distance < 50)
         {
             rabbit.transform.position = rabbitBlack.transform.position;
                 
         }
         else
         {
             rabbit.transform.position = rabbitInitialPos;
         
         }
    
     }
 //4
    
 public void Droplion()
     {
    
         float Distance = Vector3.Distance(lion.transform.position, lionBlack.transform.position);
         if (Distance < 50)
         {
             lion.transform.position = lionBlack.transform.position;
                 
         }
         else
         {
             lion.transform.position = lionInitialPos;
         
         }
    
     }
 //5
    
 public void Dropgoat()
     {
    
         float Distance = Vector3.Distance(goat.transform.position, goatBlack.transform.position);
         if (Distance < 50)
         {
             goat.transform.position =goatBlack.transform.position;
                 
         }
         else
         {
             goat.transform.position = goatInitialPos;
         
         }
     }
 }
dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@renald657-0383, currently Micrsoft Q&A doesn't support Unity, you could ask the question in StackOverflow


0 Votes 0 ·

0 Answers