From 17a86b5bc20f7786597d56dc05bef333805873f8 Mon Sep 17 00:00:00 2001 From: Teascade Date: Sun, 4 Aug 2019 01:59:18 +0300 Subject: [PATCH] Add Revolver and bullet and make shooty --- Assets/Graphics/RevolverBullet.png | Bin 0 -> 499 bytes Assets/Graphics/RevolverBullet.png.meta | 103 + Assets/Prefabs/Player.prefab | 116 +- Assets/Prefabs/Revolver.prefab | 154 + Assets/Prefabs/Revolver.prefab.meta | 7 + Assets/Prefabs/RevolverBullet.prefab | 4945 +++++++++++++++++ Assets/Prefabs/RevolverBullet.prefab.meta | 7 + Assets/Scenes/PlayerTestScene.unity | 304 +- Assets/Scripts/Bullet.cs | 11 + Assets/Scripts/Bullet.cs.meta | 11 + Assets/Scripts/Bullets.meta | 8 + Assets/Scripts/Bullets/RevolverBullet.cs | 19 + Assets/Scripts/Bullets/RevolverBullet.cs.meta | 11 + Assets/Scripts/Gun.cs | 43 + Assets/Scripts/Gun.cs.meta | 11 + Assets/Scripts/Player.cs | 23 +- Raw Assets/RevolverBullet.xcf | Bin 0 -> 1418 bytes 17 files changed, 5536 insertions(+), 237 deletions(-) create mode 100644 Assets/Graphics/RevolverBullet.png create mode 100644 Assets/Graphics/RevolverBullet.png.meta create mode 100644 Assets/Prefabs/Revolver.prefab create mode 100644 Assets/Prefabs/Revolver.prefab.meta create mode 100644 Assets/Prefabs/RevolverBullet.prefab create mode 100644 Assets/Prefabs/RevolverBullet.prefab.meta create mode 100644 Assets/Scripts/Bullet.cs create mode 100644 Assets/Scripts/Bullet.cs.meta create mode 100644 Assets/Scripts/Bullets.meta create mode 100644 Assets/Scripts/Bullets/RevolverBullet.cs create mode 100644 Assets/Scripts/Bullets/RevolverBullet.cs.meta create mode 100644 Assets/Scripts/Gun.cs create mode 100644 Assets/Scripts/Gun.cs.meta create mode 100644 Raw Assets/RevolverBullet.xcf diff --git a/Assets/Graphics/RevolverBullet.png b/Assets/Graphics/RevolverBullet.png new file mode 100644 index 0000000000000000000000000000000000000000..6491468b2587fe053bd1cdc1d56acc87dddcf92a GIT binary patch literal 499 zcmV02y>e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00CP`L_t&-(>>9@iW6ZJ#^K+4 zzHc&yyds{)U5D~PnSqs_98}SN6D{Wi^3qdTr1h2tHSP*x!Sq;fdX1;T* z^tpvc7s2)SukWANb&q>u*k=Ye1Uz~EQP=twRW<+U&AWTCT?c&|v~7iDBaaH+Cl)sb zQZjDcK1+9wzBxc{YO(P|u7i0KcnGV+&=q!9;D{gJZ5D7`4Ezzrxw z2#)}Sd$4aIOh`d4MeIAn2N42Gh6D)uPV{@H8!D!A@#y$8XLn=U3PUJC%0b^jGBFHJ zGb>c7;_().Direction; + float Rot = GetComponent().InitialRotation; + + Body.velocity = Direction * 15; + Body.rotation = Rot - 90; + } + } +} diff --git a/Assets/Scripts/Bullets/RevolverBullet.cs.meta b/Assets/Scripts/Bullets/RevolverBullet.cs.meta new file mode 100644 index 0000000..f8714fb --- /dev/null +++ b/Assets/Scripts/Bullets/RevolverBullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 092887ba145f2ff45a6c255a06b0c2ff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gun.cs b/Assets/Scripts/Gun.cs new file mode 100644 index 0000000..cc8090c --- /dev/null +++ b/Assets/Scripts/Gun.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace Saltosion.OneWeapon { + public class Gun : MonoBehaviour { + + public Bullet Bullet; + + private bool IsHeld = false; + + void Start() { + + } + + void Update() { + + } + + void OnTriggerEnter2D(Collider2D collider) { + if (IsHeld) { + return; + } + Player Player = collider.GetComponent(); + if (Player != null) { + IsHeld = true; + Player.SetGun(this); + Destroy(GetComponent()); + } + } + + public void Shoot(Vector2 position, Vector2 direction, float rotation) { + if (Bullet == null) { + Debug.LogError("THERE IS NO BULLET"); + } else { + Bullet ShotBullet = Instantiate(Bullet, position, new Quaternion()); + ShotBullet.Direction = direction.normalized; + ShotBullet.InitialRotation = rotation; + } + } + } +} diff --git a/Assets/Scripts/Gun.cs.meta b/Assets/Scripts/Gun.cs.meta new file mode 100644 index 0000000..3e98403 --- /dev/null +++ b/Assets/Scripts/Gun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c80190f5b43dadf47ae89f04f092d1ff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 513ea81..ddc42df 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -9,6 +9,11 @@ namespace Saltosion.OneWeapon { public Transform Hand; public float MoveSpeed = 50f; + private Gun Gun; + + private Vector2 GunLocation = new Vector2(0.1f, -0.7f); + private Vector3 GunRotation = new Vector3(0, 0, -90); + void Start() { } @@ -19,21 +24,31 @@ namespace Saltosion.OneWeapon { Vector2 Direction = new Vector2(X, Y).normalized; - Body.velocity = Direction * MoveSpeed * Time.deltaTime; + Body.velocity = Direction * MoveSpeed; Vector3 MousePos = Input.mousePosition; Vector3 PointedPos = Camera.main.ScreenToWorldPoint(MousePos); - Vector2 LookDirection = PointedPos - Hand.position; + Vector2 LookDirection = (PointedPos - Hand.position).normalized; var Rot = Hand.localEulerAngles; Rot.z = Mathf.Atan2(LookDirection.y, LookDirection.x) * Mathf.Rad2Deg + 90; Hand.localEulerAngles = Rot; bool Shoot = Input.GetButtonDown("Shoot"); - if (Shoot) { - Debug.Log(LookDirection.normalized); + if (Shoot && Gun != null) { + Gun.Shoot(Gun.transform.position, LookDirection, Rot.z); } } + + public void SetGun(Gun gun) { + if (Gun != null) { + Destroy(Gun.gameObject); + } + Gun = gun; + Gun.transform.parent = Hand; + Gun.transform.localPosition = GunLocation; + Gun.transform.localEulerAngles = GunRotation; + } } } diff --git a/Raw Assets/RevolverBullet.xcf b/Raw Assets/RevolverBullet.xcf new file mode 100644 index 0000000000000000000000000000000000000000..e31fce4ed9fb21c222ebb3826090eb1f7b7c7676 GIT binary patch literal 1418 zcmb7EOHUI~6uuo=m6tEnm5UJ{!37554{+gvM`!4C3hql8>O^QsTOX`6QRG#JP9HF| zOet-_2Qiwsb>qgBi3|UMi3<}aE+H5>p3`>B7;)j(d~?71opa{i-gDcqIyuGP3yt%4 zdU|^qq7B(X0(Sba29W5f_6w-}6ggn#Gly@5Q`*3UzOI0U>VWm49Q^&}|Y!~Z_C#EM9J|3M=$1b;YjfX?g ziD-=Pstw(-@Mw_lxzba^0iw4Nx{Rfx2b9`z{@;R1@5QHrAvF@_d+oK*oIc2Gc-^-n zYJyiIp_@va>Z9Z1aV7D4gH-*uRd@a@rE_q=_1-Z->8>}TZrXjLQ*M`naXMrnIIYAe z%++&hy`r80@*L8A?EyZquSoK#xVfQmV4V(q)}iTwP(Fc2+Pc-DX+yT(?$F0j(|R@z zqo6!`|HX#Jfn6XC2prElw0-Y9=sCcBa!l;QXspkDKOlxy6Rlmtj59n}z7ptLSb27$XV6JCz_sITFfk2RyLWOeK@0~lluVHY|bdJCBOdQU*#Rgy;9e7U@u zH;d~=T3dr{P1AE)Drw{Z@~PDP!x?==$M3bfm@mGl=zFv-6Z^eBzn|@L@Of~cU-St+ zuXq)}D++=n3f>_fV}c|Mi6STbko~OB$MwS?H}GBbO9K+7i}aDDLD}u!lckXxOyB}8 z`AfhrjxaV9kOT6tED!Hu_X3hn@CI6UIDifhxY-f-iPy0i_Fb$6fa?Tk!U=~y$Dqvv z(A-2Vv0Hd7piC&Cgc^#5_}u1UrV7XU_KT!Y^G^PD20y literal 0 HcmV?d00001