- Home /
I need help with overlapping sprites and teleporting
I'm developing a simple 2d Android game in which you have to tap at the right moment to score a point. It consists of a bar with a red zone, an orange zone and a green zone, the yellow indicator moves along the bar. This is the bar: http://imgur.com/a/K13pB04
I want to be able to teleport the yellow indicator back by 2/3 of the screen width if you tap when it's overlapping the green and the orange zone (which extends behind the green zone). I'll add the code that runs if you tap when the indicator is on the orange zone later.
This is the script I attached to the yellow bar:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BarMovement : MonoBehaviour
{
float VelocityX = 3;
int SW = Screen.width;
public Rigidbody2D BarProgress;
void Start()
{
BarProgress = GetComponent<Rigidbody2D>();
}
void Update()
{
BarProgress.velocity = new Vector2(VelocityX, 0);
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "OrangeZone" & other.gameObject.tag == "GreenZone" & Input.GetMouseButtonDown(0))
{
BarProgress.transform.position = new Vector2(-(SW * 2 / 3), 0);
}
}
}
}
But when I click while testing nothing happens and the yellow bar keeps going forward. The sprites are on the same Z level and the tags are correct so I don't know what's wrong with the code.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
simple overlap in 2d 1 Answer
Unity Sprites Overlapping, slightly see-through (2D game) 2 Answers
Trying to reset lvl on collsion 1 Answer