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);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Game07/Game07.cs.meta
Normal file
11
Assets/Scripts/Game07/Game07.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f83d9d6aa83ab9469300b45a3c4b843
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Scripts/Game07/PlayerController07.cs
Normal file
54
Assets/Scripts/Game07/PlayerController07.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PlayerController07 : MonoBehaviour{
|
||||
|
||||
public GameObject death;
|
||||
public string menuScene;
|
||||
public string[] scenes;
|
||||
public Image timeBar;
|
||||
public float maxTime = 5;
|
||||
float currentTime;
|
||||
Rigidbody2D rb2d;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
currentTime = maxTime;
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
currentTime -= 1 * Time.deltaTime;
|
||||
timeBar.transform.localScale = new Vector2(currentTime / maxTime, timeBar.transform.localScale.y);
|
||||
if (currentTime <= 0){
|
||||
StartCoroutine(Death());
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerStay2D(Collider2D col){
|
||||
if (rb2d.velocity.y < 0){
|
||||
CompleteLevel();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Death(){
|
||||
Time.timeScale = 0;
|
||||
death.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4f);
|
||||
LoseGame();
|
||||
}
|
||||
|
||||
public void CompleteLevel(){
|
||||
string scene = scenes[Random.Range(0, scenes.Length - 1)];
|
||||
LevelLoader.Instance.LoadLevel(scene);
|
||||
}
|
||||
|
||||
public void LoseGame(){
|
||||
Debug.LogError(SceneManager.GetActiveScene().name);
|
||||
LevelLoader.Instance.LoadLevel(menuScene);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Game07/PlayerController07.cs.meta
Normal file
11
Assets/Scripts/Game07/PlayerController07.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3373a59045d675146b4aa634b9335f5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue