Click here to Skip to main content
15,900,500 members

Comments by Ethir Pakalela (Top 2 by date)

Ethir Pakalela 27-Sep-21 23:01pm View    
Hi! Thanks for the reply. YES its exactly what i need:

this is the updated code of the above one:

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

public class manager1 : MonoBehaviour
{
     public GameObject[] animals;

    public GameObject[] blackAnimals;

    Vector3[] animalStartPos;

    Vector3[] animalBlackStartPos;

    void Start()

    {

        animalStartPos = new Vector3[animals.Length];

        animalBlackStartPos = new Vector3[blackAnimals.Length];

        for (int i = 0; i < animals.Length; i++)

        {

            animalStartPos[i] = animals[i].transform.position;

            animalBlackStartPos[i] = blackAnimals[i].transform.position;

        }            

    }

    public void dragAnimal(GameObject animal)

    {

        animal.transform.position = Input.mousePosition;

    }

    public void dropAnimal(GameObject animal)

    {

        int index = System.Array.IndexOf(animals, animal);

        float dist = Vector3.Distance(animal.transform.position, blackAnimals[index].transform.position);

        if (dist < 50)

            animal.transform.position = blackAnimals[index].transform.position;

        else animal.transform.position = animalStartPos[index];

    }
}

Ethir Pakalela 27-Sep-21 22:59pm View    
Deleted
Hi! Thanks for the reply. yes its exactly what i need:

this is the updated code of the above one:

using System.Collections;using System.Collections.Generic;using UnityEngine;public class manager1 : MonoBehaviour{     public GameObject[] animals;    public GameObject[] blackAnimals;    Vector3[] animalStartPos;    Vector3[] animalBlackStartPos;    void Start()    {        animalStartPos = new Vector3[animals.Length];        animalBlackStartPos = new Vector3[blackAnimals.Length];        for (int i = 0; i < animals.Length; i++)        {            animalStartPos[i] = animals[i].transform.position;            animalBlackStartPos[i] = blackAnimals[i].transform.position;        }                }    public void dragAnimal(GameObject animal)    {        animal.transform.position = Input.mousePosition;    }    public void dropAnimal(GameObject animal)    {        int index = System.Array.IndexOf(animals, animal);        float dist = Vector3.Distance(animal.transform.position, blackAnimals[index].transform.position);        if (dist < 50)            animal.transform.position = blackAnimals[index].transform.position;        else animal.transform.position = animalStartPos[index];    }}