Added collectible to recharge grapple
This commit is contained in:
parent
ede5429ff8
commit
76a7333455
116
Assets/Prefabs/Collectible.prefab
Normal file
116
Assets/Prefabs/Collectible.prefab
Normal file
@ -0,0 +1,116 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &7330076085198802814
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7330076085198802813}
|
||||
- component: {fileID: 7330076085198802810}
|
||||
- component: {fileID: 7330076085198802811}
|
||||
- component: {fileID: 7330076085198802812}
|
||||
- component: {fileID: 7330076085198802809}
|
||||
m_Layer: 2
|
||||
m_Name: Collectible
|
||||
m_TagString: Collectible
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7330076085198802813
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7330076085198802814}
|
||||
m_LocalRotation: {x: -0, y: -0, z: 0.18729897, w: 0.982303}
|
||||
m_LocalPosition: {x: 17.7, y: 6.27, z: 0}
|
||||
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 21.59}
|
||||
--- !u!33 &7330076085198802810
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7330076085198802814}
|
||||
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &7330076085198802811
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7330076085198802814}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, 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: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!136 &7330076085198802812
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7330076085198802814}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_Enabled: 1
|
||||
m_Radius: 0.5
|
||||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &7330076085198802809
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7330076085198802814}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fad65f8e0d6747f4b8e79104b58b08b6, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
amount: 1
|
||||
rotSpeed: 5
|
||||
timeToAppear: 3
|
||||
7
Assets/Prefabs/Collectible.prefab.meta
Normal file
7
Assets/Prefabs/Collectible.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b753a3910de2c134687d0e6e21ad6a74
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
34
Assets/Scripts/Collectible.cs
Normal file
34
Assets/Scripts/Collectible.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Collectible : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private int amount;
|
||||
[SerializeField]
|
||||
private float rotSpeed;
|
||||
[SerializeField]
|
||||
private float timeToAppear;
|
||||
|
||||
void Update()
|
||||
{
|
||||
transform.Rotate(0, rotSpeed, 0, Space.World);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other) {
|
||||
if(other.gameObject.tag.Equals("Player")){
|
||||
other.gameObject.GetComponent<GrappleHook>().AddCharge(amount);
|
||||
Vanish();
|
||||
}
|
||||
}
|
||||
|
||||
private void Vanish(){
|
||||
gameObject.SetActive(false);
|
||||
Invoke("Appear", timeToAppear);
|
||||
}
|
||||
|
||||
private void Appear(){
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Collectible.cs.meta
Normal file
11
Assets/Scripts/Collectible.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fad65f8e0d6747f4b8e79104b58b08b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -24,6 +24,8 @@ public class GrappleHook : MonoBehaviour
|
||||
private LayerMask grappleableLayer;
|
||||
[SerializeField]
|
||||
private float aimSpeed = 50f;
|
||||
[SerializeField]
|
||||
private int charges = 5;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField]
|
||||
@ -43,6 +45,7 @@ public class GrappleHook : MonoBehaviour
|
||||
float changingLengthDir = 0;
|
||||
private Vector3 currGrappleEndPos;
|
||||
private GameObject hookedTo; // The obj we are hooked to
|
||||
|
||||
public GameObject HookedTo{get => hookedTo; set => hookedTo = value;}
|
||||
|
||||
#region private methods
|
||||
@ -85,9 +88,17 @@ public class GrappleHook : MonoBehaviour
|
||||
|
||||
if(Physics.Raycast(gameObject.transform.position, aimDir, out hit, maxGrappleDist, grappleableLayer)){
|
||||
hitMarkerRect.anchoredPosition = WorldToUI(hit.point);
|
||||
if(charges > 0){
|
||||
hitMarkerRect.gameObject.GetComponent<Image>().color = Color.green;
|
||||
}else{
|
||||
hitMarkerRect.gameObject.GetComponent<Image>().color = Color.red;
|
||||
}
|
||||
|
||||
|
||||
if(grappling){
|
||||
StartGrapple(hit);
|
||||
}else{
|
||||
grappling = false;
|
||||
}
|
||||
}else{
|
||||
hitMarkerRect.gameObject.GetComponent<Image>().color = Color.red;
|
||||
@ -112,8 +123,9 @@ public class GrappleHook : MonoBehaviour
|
||||
|
||||
}
|
||||
private void StartGrapple(RaycastHit hit){
|
||||
grappled = true;
|
||||
grappling = false;
|
||||
if(charges <= 0)return;
|
||||
grappled = true;
|
||||
|
||||
//Display
|
||||
hitMarkerRect.gameObject.SetActive(false);
|
||||
@ -142,6 +154,7 @@ public class GrappleHook : MonoBehaviour
|
||||
}
|
||||
hookedTo = hit.transform.gameObject;
|
||||
currGrappleEndPos = transform.position;
|
||||
charges--;
|
||||
}
|
||||
|
||||
private void EndGrapple(){
|
||||
@ -183,6 +196,10 @@ public void Unhook(GameObject hookedObj){
|
||||
if(hookedObj.Equals(hookedTo))
|
||||
EndGrapple();
|
||||
}
|
||||
|
||||
public void AddCharge(int amount){
|
||||
charges += amount;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region InputActions
|
||||
|
||||
@ -5,6 +5,7 @@ TagManager:
|
||||
serializedVersion: 2
|
||||
tags:
|
||||
- Vanishing
|
||||
- Collectible
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user