Projektile implementiert mit *KitchenGun*

This commit is contained in:
Maximilian Wagner 2023-06-19 01:52:18 +02:00
parent 648b2b8b76
commit fc6758acf3
4 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,108 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3428666236834465257
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3583860399244231701}
- component: {fileID: 186598407986526325}
- component: {fileID: 4444577561583263346}
m_Layer: 0
m_Name: Projectile
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3583860399244231701
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3428666236834465257}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -4.472, y: -2.308, z: 0}
m_LocalScale: {x: 0.3, y: 0.3, z: 0.3}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &186598407986526325
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3428666236834465257}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!50 &4444577561583263346
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3428666236834465257}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0
m_GravityScale: 0
m_Material: {fileID: 6200000, guid: 9a162dcdc92b4194ba53630f8785bed1, type: 2}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 43403bc203c88a14d8cac1157caa794d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,58 @@
using System.Collections;
using UnityEngine;
public class KitchenGun : MonoBehaviour
{
// The shot projectiles
public GameObject projectilePrefab;
// Time between shots, game needs to be restarted to take effect
public float shotInterval = 1f;
// Speed of projectiles
public Vector2 shotSpeed = new Vector2(1f, 0f);
// Smallest step size for shot speed
private short shotSpeedStepSize = 50;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("RecurringBang",0f,shotInterval);
}
// Update is called once per frame
void Update()
{
}
void RecurringBang()
{
StartCoroutine("Bang");
}
private IEnumerator Bang()
{
Transform t = transform;
Vector3 position = t.position;
// create projectile
GameObject projectile = Instantiate(projectilePrefab,
position,
t.rotation);
// determine correct force vector
Vector2 force = shotSpeed;
if (t.localScale.x < 0) {
force *= -1;
}
force *= shotSpeedStepSize;
// add force to projectile
Rigidbody2D pBody = projectile.GetComponent<Rigidbody2D>();
pBody.AddRelativeForce(force);
yield return new WaitForSeconds(shotInterval);
Debug.Log("Bang!");
Destroy(projectile);
}
}

View File

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