Projectiles work now + Endboss Level started

This commit is contained in:
GungHolo
2023-06-21 16:54:02 +02:00
parent be62ab1315
commit 6476942b43
25 changed files with 8264 additions and 94 deletions

View File

@@ -1,14 +1,21 @@
using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEngine.Serialization;
/*
WICHTIG
Für dieses Script muss ein Object namens "RespawnProjectile" vorhanden sein an dem man wieder spawnt
Collider Disabled Seconds muss so gesetzt werden das das Projectil aus der Quelle rauskommt ohne zerstört zu werden
*/
public class KitchenGun : MonoBehaviour
{
// The shot projectiles
public GameObject projectilePrefab;
// Time between shots, game needs to be restarted to take effect
public float shotIntervalSeconds = 1f;
// Time alive for the projectiles
// Time alive for the projectiles or until they hit something
public float shotAliveSeconds = 1f;
// Time until collider gets enabled
public float colliderDisabledSeconds = .2f;
@@ -43,16 +50,10 @@ public class KitchenGun : MonoBehaviour
GameObject projectile = Instantiate(projectilePrefab,
position,
t.rotation);
projectile.transform.parent = GameObject.Find("Dim2").transform;
// determine correct force vector
Vector2 force = shotSpeed;
if (t.localScale.x < 0) {
force *= -1;
}
force *= shotSpeedStepSize;
// add force to projectile
projectile.GetComponent<Rigidbody2D>().AddRelativeForce(force);
projectile.GetComponent<Rigidbody2D>().velocity = shotSpeed;
// wait until enabling collider
yield return new WaitForSeconds(colliderDisabledSeconds);
@@ -62,5 +63,6 @@ public class KitchenGun : MonoBehaviour
yield return new WaitForSeconds(shotAliveSeconds);
Destroy(projectile);
}
}

View File

@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Projectile : MonoBehaviour
{
private Vector2 vel;
private Rigidbody2D rb;
private BoxCollider2D bc;
void Start()
{
rb = GetComponent<Rigidbody2D>();
bc = GetComponent<BoxCollider2D>();
vel = rb.velocity;
GetComponent<Collider2D>().enabled = false;
}
void FixedUpdate()
{
rb.velocity = vel;
}
void OnTriggerEnter2D(Collider2D bc)
{
Destroy(gameObject);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 566c8e790367e43488e83ac42d5b24a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,11 +2,14 @@ using UnityEngine;
public class respawn : MonoBehaviour
{
public GameObject player;
public Transform respawnPoint;
private GameObject player;
[SerializeField] private Transform respawnPoint;
void Start()
{
player = GameObject.Find("Frank");
}
void Update()

View File

@@ -0,0 +1,26 @@
using UnityEngine;
public class respawnProjectile : MonoBehaviour
{
private GameObject player;
private Transform respawnPoint;
void Start()
{
player = GameObject.Find("Frank");
respawnPoint = GameObject.Find("RespawnProjectile").transform;
}
void Update()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
player.transform.position = respawnPoint.position;
Debug.Log("Respawn: Move");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0a49909080c12c489367e37b06e7169
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: