Refactoring Prefabs

This commit is contained in:
pbg2h23akl
2024-06-14 16:58:09 +02:00
parent 6bd36f657f
commit 781ca8706a
13 changed files with 417 additions and 15 deletions

View File

@@ -10,16 +10,20 @@ public class BulletMoving : MonoBehaviour
[SerializeField]
private Rigidbody rb;
private Vector3 direction = new Vector3(0f,0f,0f);
private
// Start is called before the first frame update
void Start()
{
rb = parent.GetComponent<Rigidbody>();
direction = transform.position - parent.transform.position;
}
// Update is called once per frame
void Update()
{
rb.velocity = dataBullet.direction * dataBullet.speed;
rb.velocity = direction * dataBullet.speed;
}
}

View File

@@ -10,8 +10,6 @@ public class DataBullet : ScriptableObject
public float speed = 5f;
public Vector3 direction = new Vector3();
public int ammo;
public void setDamage(float damage){

View File

@@ -10,9 +10,8 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9e1d27c11e7949e4fa59cefee3928ca4, type: 3}
m_Name: BulletData1
m_Name: DataBullet
m_EditorClassIdentifier:
damage: 10
speed: 2
direction: {x: 1, y: 0, z: 0}
speed: 10
ammo: 4

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 215ad7d91b06f2741b40dc3806033238
guid: cafd241bae342f446ae8141cc5d72daf
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponScript : MonoBehaviour
{
public GameObject parent;
public GameObject bullet;
public void shoot(){
if(Input.GetKeyDown(KeyCode.Mouse0)){
Instantiate(bullet,transform.position,parent.transform.rotation);
}
}
void Start()
{
}
// Update is called once per frame
void Update()
{
shoot();
}
}

View File

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