init
This commit is contained in:
commit
9afd57306d
323 changed files with 204673 additions and 0 deletions
34
Assets/Scripts/Game07/Game07.cs
Normal file
34
Assets/Scripts/Game07/Game07.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue