Question by
NA_Wolfrick · Apr 08, 2019 at 05:58 PM ·
collisionmaskvisible
How to collide with an object only when a sprite mask is over it?
I'm in the middle of creating a 2D maze game and I'm using a 2D sprite mask that follows the mouse around so you can find collectibles hidden beneath the tileset. One problem, the objects have a collision box and if you run into even when the sprite mask isn't over it you still collide with it. I want it to work so you can only grab the collectible when the sprite mask (aka the mouse) is over it.
Sprite Mask / Mouse Code:
using UnityEngine;
using System.Collections;
public class MouseMovements : MonoBehaviour
{
//Variables
private Vector3 mousePosition;
public float moveSpeed = 0.1f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
//Follow Mouse
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
}
}
capture.png
(17.2 kB)
Comment