This commit is contained in:
Gerard Gascón 2025-04-24 14:20:42 +02:00
commit 9afd57306d
323 changed files with 204673 additions and 0 deletions

View file

@ -0,0 +1,34 @@
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);
}
}
}