Prefabs und Scripts nochmal verbessert

This commit is contained in:
klikev
2024-06-14 19:08:04 +02:00
parent 781ca8706a
commit 588a0f1212
12 changed files with 386 additions and 222 deletions

View File

@@ -4,26 +4,36 @@ using UnityEngine;
public class BulletMoving : MonoBehaviour
{
public GameObject parent;
public GameObject child;
public DataBullet dataBullet;
public float lifetime = 3f;
[SerializeField]
private Rigidbody rb;
private Vector3 direction = new Vector3(0f,0f,0f);
private float time = 0f;
private
private void die(float lifetime){
if(time > lifetime){
GameObject.Destroy(this.gameObject);
}
}
// Start is called before the first frame update
void Start()
{
rb = parent.GetComponent<Rigidbody>();
direction = transform.position - parent.transform.position;
rb = this.GetComponent<Rigidbody>();
direction = child.transform.position - transform.position;
}
// Update is called once per frame
void Update()
{
rb.velocity = direction * dataBullet.speed;
die(lifetime);
time += Time.deltaTime;
}
}

View File

@@ -13,5 +13,5 @@ MonoBehaviour:
m_Name: DataBullet
m_EditorClassIdentifier:
damage: 10
speed: 10
speed: 20
ammo: 4

View File

@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spin : MonoBehaviour
{
private float time = 0;
public float speed;
public void spinY(float add){
transform.rotation = Quaternion.Euler(0f,220f + add,0f);
}
void Start()
{
}
// Update is called once per frame
void Update()
{
time += Time.deltaTime + speed * Time.deltaTime;
spinY(time);
}
}

View File

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

View File

@@ -5,13 +5,13 @@ using UnityEngine;
public class WeaponScript : MonoBehaviour
{
public GameObject parent;
public GameObject spawnpoint;
public GameObject bullet;
public void shoot(){
private void shoot(){
if(Input.GetKeyDown(KeyCode.Mouse0)){
Instantiate(bullet,transform.position,parent.transform.rotation);
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
}