using System.Collections; using System.Collections.Generic; using UnityEngine; public class Game07 : MonoBehaviour{ public float rotationForce; float rotZ; bool shoot; public Rigidbody2D rb2d; public float throwForce; public Transform target; // Start is called before the first frame update void Start(){ rb2d.gravityScale = 0; } // Update is called once per frame void Update(){ if (!shoot){ rotZ = Mathf.Sin(Time.time * 3) * rotationForce; //tweak this to change frequency transform.rotation = Quaternion.AngleAxis(rotZ, Vector3.forward); } if (Input.GetKeyDown(KeyCode.Space) && !shoot){ shoot = true; Vector2 difference = target.position - transform.position; difference.Normalize(); rb2d.gravityScale = 2; rb2d.AddForce(difference * throwForce, ForceMode2D.Impulse); } } }