Question by
Reorso · Mar 07, 2016 at 11:17 AM ·
collisionupdatevariablescollision2d
Why after changing variable s value it returns at the original value?
Hi, thanks for reading, i'm new to unity and i'm trying to make a 2d game just for learning something on this engine. This code make enemies change direction when they hit a object tagged "Wall", but when i try it enemies still run against wall.
using UnityEngine;
using System.Collections;
public class enemiesController : MonoBehaviour {
Vector3 endposition;
private float Edirection;
// Use this for initialization
void Start () {
Edirection = 1f;
}
// Update is called once per frame
void FixedUpdate () {
print (Edirection);
endposition.Set (Edirection, 0, 0);
endposition = endposition * 2 * Time.deltaTime;
transform.position += endposition;
}
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.tag == "Wall") {
Edirection = -1f;
print("collision");
}
}
}
I tried to put some print functions in and the problem seems to be that Edirection continue to change value after the collision, whitout any new collisions.
screen of console:
screen.png
(37.1 kB)
Comment
Your answer
Follow this Question
Related Questions
How to destroy an prefab Object after the second hit? 2 Answers
Horrible Collison 2D -- 1 Answer
Counting Activation of specific panels, not updating Variable? 2 Answers
collision not working after enabling it twice 0 Answers
Collision not working 1 Answer