Question by
rudisky · Aug 02, 2016 at 05:11 PM ·
spritesdrag-and-drop
Sprite superimpose over other sprite when drag over.
hi i'm new in Unity and i have the next problem: i'm building a game for android and Ios that is like a simulator where i have to drag sprites to other spriter to simulate action, i have sprites for tools and for objectives. the problem that i have now is when i drag a tool sprite and pass over other tool sprite they absorb each other and i can't separate them.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class movimiento : MonoBehaviour {
public float speed = 0.1F;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.touchCount > 0)
print(Input.touchCount);
//Gets the world position of the mouse on the screen
Vector2 mousePosition = Camera.main.ScreenToWorldPoint( Input.mousePosition );
//Checks whether the mouse is over the sprite
bool overSprite = this.GetComponent<SpriteRenderer>().bounds.Contains( mousePosition );
//If it's over the sprite
if (overSprite)
{
//If we've pressed down on the mouse (or touched on the iphone)
if (Input.GetButton("Fire1"))
{
//Set the position to the mouse position
this.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
Camera.main.ScreenToWorldPoint(Input.mousePosition).y,
0.0f);
}
}
}
}
Comment