Question by
mohamed_elgabry · Dec 09, 2017 at 08:19 PM ·
collider2d game
Need to move gameObject when triggering collider
I need to make a game Object (other) to move when triggering this trigger function towards a given transform as in the code below but it is not working:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GravityMirror : MonoBehaviour { public int mirrorNum; public bool enabled; public Transform moveTo;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "EnemyGravity")
{
other.transform.position =
Vector3.MoveTowards(other.transform.position,
moveTo.transform.position,
FindObjectOfType<GravityBulletE>().speed * Time.deltaTime);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Drop object on click and create a new one 0 Answers
Trigger Collinder doesnt work with Input.GetKey 1 Answer
Audio Trigger 2D in C#? 1 Answer
Cannot call trigger-event when dragging object via touch 1 Answer
Make Blocks stay in the grid 0 Answers