- Home /
transform.forward makes my GameObject Disappear
All I would like to do is shoot a laser in the direction I gave it. I set the rotation when I instantiated it, and that works fine. However, for whatever reason, the script doesn't seem to like it when I use "transform.forward" or "Vector3.forward". I handle the laser's movement and behavior in this script and I instantiate it in a different one.
public class RedLaser : MonoBehaviour {
private Rigidbody2D rb;
public float speed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
void Update () {
if (transform.position.y >= 6.0f) {
Destroy(gameObject);
}
}
void FixedUpdate () {
//transform.position += transform.forward * speed * Time.deltaTime;
//rb.AddForce(transform.forward * speed, ForceMode2D.Force);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}
I'm pretty sure the problem is here. When I hit play the lasers just disappear. No error shows up or anything. I put the laser prefab in the game scene and selected it, then hit play: the laser is in the scene and it's moving. I just can't see it for some reason. However, the script IS fine with me using "Vector3.up". It just doesn't like "transform.forward" or "Vector3.forward". I could really use some help!
Thanks
Just want to make it clear. The laser is in the hierarchy but it's not visible, right? What does the laser made of? have you checked the renderer component?
Your answer
Follow this Question
Related Questions
Locking gameobject to rotating floor 0 Answers
I want a better explination than the one in unitys tutorial 2 Answers
Problem with C# "if" statement? 2 Answers
Change size of an object up to a limit 2 Answers
Multiple Cars not working 1 Answer