Question by
oussamahassini6 · May 23, 2018 at 08:42 AM ·
scripting problem2d gametrigger2d-physics
My gameobject stops moving after entering the trigger??
the arrow stops moving after entering the trigger. even if go =true. and the stop trigger is the big circle.!
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Movement : MonoBehaviour { public InsStart intstart; public Text scoreText; public Quaternion rot; // private int score; private int add; public float speed = 25f;
public GameObject Player;
public float speed1;
public GameObject test;
private Rigidbody2D rb;
public bool go;
public GameObject point;
// Use this for initialization
void Start()
{
intstart = GameObject.FindWithTag("papa").GetComponent<InsStart>();
go = false;
rb = GetComponent<Rigidbody2D>();
transform.position = new Vector2(0.0f, 3.41f);
}
// Update is called once per frame
void Update()
{
rot = point.transform.rotation;
if (intstart.instantiate == true)
{
Instantiate(point, test.transform.position,rot);
}
if (go==true)
{
transform.position += transform.up * Time.deltaTime * speed1;
return;
}
Vector2 dir = this.transform.position - Vector3.zero;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg + 90;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.RotateAround(Vector2.zero, Vector3.back, speed * Time.deltaTime);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "cibl")
{
Application.LoadLevel("scene");
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "stop")
{
go = false;
}
}
private void OnTriggerExit2D(Collider2D col)
{
if (col.gameObject.tag == "pizza")
{
go = true;
add += 2;
scoreText.text = add.ToString();
}
if (col.gameObject.tag == "stop")
{
go = false;
}
}
public void Onclick()
{
if (go != true)
go = true;
}
}
capture-decran-159.png
(229.0 kB)
Comment
What would you like the pin to do when it hits the OnTriggerEnter CircleCollider2D?