So I am creating a script for my 2D fighting game, and the script spawns a boomerang when I press the "c" key, and it is supposed to fly across the scene until it passes the camera bounds, at which it becomes invisible, it works in that it spins - as it should- and it spawns from the "c" key , but it doesn't move, here is the script; I would love some help.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody2D))]
public class appleBoomerang : MonoBehaviour {
[SerializeField]
private float speed;
private Rigidbody2D myRigidbody;
private Vector2 direction;
// Use this for initialization
void Start () {
myRigidbody = GetComponent();
}
void FixedUpdate()
{
transform.Rotate(new Vector3(0, 0, 1) * speed);
myRigidbody.velocity = direction * speed;
}
// Update is called once per frame
void Update () {
}
void OnBecameInvisible()
{
Destroy(gameObject);
}
}
P.S. I am very new to unity, so its probably very obvious to most what the problem is. Also, this script is only for the knife, the spawning script is ok.
↧