Prefabs und Scripts nochmal verbessert
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -13,5 +13,5 @@ MonoBehaviour:
|
||||
m_Name: DataBullet
|
||||
m_EditorClassIdentifier:
|
||||
damage: 10
|
||||
speed: 10
|
||||
speed: 20
|
||||
ammo: 4
|
||||
|
26
Plunderblock/Assets/Scripts/ScriptsKevin/Spin.cs
Normal file
26
Plunderblock/Assets/Scripts/ScriptsKevin/Spin.cs
Normal 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);
|
||||
}
|
||||
}
|
11
Plunderblock/Assets/Scripts/ScriptsKevin/Spin.cs.meta
Normal file
11
Plunderblock/Assets/Scripts/ScriptsKevin/Spin.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a156f4aad04544419b7b8a3c0a2294d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user