From 048011d05cc616ae7595db0c32c38155fb739528 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 26 Apr 2019 11:31:04 -0700 Subject: [PATCH] Sword Script for Spring2019 CompSci Club Project This script spawns the sword object when the player presses the "p" key --- Spring2019/Assets/Prefabs/Sword.prefab | 110 ++++++++++++++++++ Spring2019/Assets/Prefabs/Sword.prefab.meta | 8 ++ .../Assets/Scripts/Player/DestroySword.cs | 13 +++ .../Scripts/Player/DestroySword.cs.meta | 12 ++ .../Assets/Scripts/Player/SwordAttack.cs | 24 ++++ .../Assets/Scripts/Player/SwordAttack.cs.meta | 14 +++ 6 files changed, 181 insertions(+) create mode 100644 Spring2019/Assets/Prefabs/Sword.prefab create mode 100644 Spring2019/Assets/Prefabs/Sword.prefab.meta create mode 100644 Spring2019/Assets/Scripts/Player/DestroySword.cs create mode 100644 Spring2019/Assets/Scripts/Player/DestroySword.cs.meta create mode 100644 Spring2019/Assets/Scripts/Player/SwordAttack.cs create mode 100644 Spring2019/Assets/Scripts/Player/SwordAttack.cs.meta diff --git a/Spring2019/Assets/Prefabs/Sword.prefab b/Spring2019/Assets/Prefabs/Sword.prefab new file mode 100644 index 0000000..e39657e --- /dev/null +++ b/Spring2019/Assets/Prefabs/Sword.prefab @@ -0,0 +1,110 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1891271387985600} + m_IsPrefabParent: 1 +--- !u!1 &1891271387985600 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4262017486736852} + - component: {fileID: 33937454702079612} + - component: {fileID: 65828148411554472} + - component: {fileID: 23842842954658420} + - component: {fileID: 114629118256849782} + m_Layer: 0 + m_Name: Sword + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4262017486736852 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1891271387985600} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -6.6099997, y: 2.2, z: -8.86} + m_LocalScale: {x: 0.07035831, y: 1.8351282, z: 0.23272918} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!23 &23842842954658420 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1891271387985600} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &33937454702079612 +MeshFilter: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1891271387985600} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!65 &65828148411554472 +BoxCollider: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1891271387985600} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &114629118256849782 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1891271387985600} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 984c013890b416a4097b0acd2f4b69f2, type: 3} + m_Name: + m_EditorClassIdentifier: + Sword: {fileID: 0} diff --git a/Spring2019/Assets/Prefabs/Sword.prefab.meta b/Spring2019/Assets/Prefabs/Sword.prefab.meta new file mode 100644 index 0000000..18a54e7 --- /dev/null +++ b/Spring2019/Assets/Prefabs/Sword.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c58b7eb064e448e4d9c3648634adb079 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Spring2019/Assets/Scripts/Player/DestroySword.cs b/Spring2019/Assets/Scripts/Player/DestroySword.cs new file mode 100644 index 0000000..493353f --- /dev/null +++ b/Spring2019/Assets/Scripts/Player/DestroySword.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DestroySword : MonoBehaviour +{ + public GameObject Sword; + // Use this for initialization + void Start() + { + Destroy(Sword, 1f); + } +} diff --git a/Spring2019/Assets/Scripts/Player/DestroySword.cs.meta b/Spring2019/Assets/Scripts/Player/DestroySword.cs.meta new file mode 100644 index 0000000..1d936e5 --- /dev/null +++ b/Spring2019/Assets/Scripts/Player/DestroySword.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 984c013890b416a4097b0acd2f4b69f2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - Sword: {fileID: 1891271387985600, guid: c58b7eb064e448e4d9c3648634adb079, type: 2} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Spring2019/Assets/Scripts/Player/SwordAttack.cs b/Spring2019/Assets/Scripts/Player/SwordAttack.cs new file mode 100644 index 0000000..febf5e9 --- /dev/null +++ b/Spring2019/Assets/Scripts/Player/SwordAttack.cs @@ -0,0 +1,24 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +public class SwordAttack : MonoBehaviour + +{ + public GameObject player; + public Transform Spawnpoint; + public GameObject Sword; + void Update() + { + SwordSlash(); + } + void SwordSlash() + { + if (Input.GetKeyDown("p")) + { + Instantiate(Sword, Spawnpoint.position, transform.rotation * Quaternion.Euler(90, 0, 0)); + } + + + } +} \ No newline at end of file diff --git a/Spring2019/Assets/Scripts/Player/SwordAttack.cs.meta b/Spring2019/Assets/Scripts/Player/SwordAttack.cs.meta new file mode 100644 index 0000000..a6652c2 --- /dev/null +++ b/Spring2019/Assets/Scripts/Player/SwordAttack.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: c4fa8b7d9eb14f5439663af775c3c679 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - player: {instanceID: 0} + - Spawnpoint: {instanceID: 0} + - Sword: {instanceID: 0} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: