Added clouds and followcam

This commit is contained in:
Trianta 2024-02-19 19:52:08 -06:00
parent d882af77bb
commit 6c2120b6f8
17 changed files with 609 additions and 64 deletions

View File

@ -0,0 +1,85 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Mat_Cloud
m_Shader: {fileID: 10, guid: 0000000000000000f000000000000000, type: 0}
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Illum:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _Emission: 1
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f7a2c078722fbbaea98f88a6de8d6028
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!134 &13400000
PhysicMaterial:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PMat_Projectile
dynamicFriction: 0.6
staticFriction: 0.6
bounciness: 1
frictionCombine: 0
bounceCombine: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6bdc5844ed671652eae3b3cd32138797
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 13400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,54 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8854510988329328583
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8854510988329328577}
- component: {fileID: 8854510988329328582}
m_Layer: 0
m_Name: Cloud
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8854510988329328577
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8854510988329328583}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &8854510988329328582
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8854510988329328583}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f76c184ad3c2bda52b334b0ca1447d5d, type: 3}
m_Name:
m_EditorClassIdentifier:
cloudSphere: {fileID: 4832263485272446975, guid: 1c13e0c08297bcad389c6724bc56039f, type: 3}
numSpheresMin: 6
numSpheresMax: 10
sphereOffsetScale: {x: 5, y: 2, z: 1}
sphereScaleRangeX: {x: 4, y: 8}
sphereScaleRangeY: {x: 3, y: 4}
sphereScaleRangeZ: {x: 2, y: 4}
scaleYMin: 2

View File

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

View File

@ -0,0 +1,85 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4832263485272446975
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4832263485272446970}
- component: {fileID: 4832263485272446969}
- component: {fileID: 4832263485272446968}
m_Layer: 0
m_Name: CloudSphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4832263485272446970
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4832263485272446975}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &4832263485272446969
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4832263485272446975}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &4832263485272446968
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4832263485272446975}
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: f7a2c078722fbbaea98f88a6de8d6028, 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}

View File

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

View File

@ -92,7 +92,7 @@ SphereCollider:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7364702671587352604}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: 6bdc5844ed671652eae3b3cd32138797, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
@ -112,5 +112,5 @@ Rigidbody:
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
m_Constraints: 120
m_CollisionDetection: 1

View File

@ -466,6 +466,37 @@ Transform:
m_Father: {fileID: 1540568165}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &289392414
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 289392415}
m_Layer: 0
m_Name: CloudAnchor
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &289392415
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 289392414}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &595571173
GameObject:
m_ObjectHideFlags: 0
@ -475,6 +506,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 595571174}
- component: {fileID: 595571175}
m_Layer: 0
m_Name: LaunchPoint
m_TagString: Untagged
@ -497,6 +529,18 @@ Transform:
m_Father: {fileID: 1540568165}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 15, z: 0}
--- !u!122 &595571175
Halo:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 595571173}
m_Enabled: 1
m_Color:
serializedVersion: 2
rgba: 4290756543
m_Size: 3
--- !u!1 &1540568164
GameObject:
m_ObjectHideFlags: 0
@ -559,6 +603,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 79f74d378cdc33350830dd6c4adcadde, type: 3}
m_Name:
m_EditorClassIdentifier:
prefabProjectile: {fileID: 7364702671587352604, guid: bdf63a487fce38097b5e77b912360559, type: 3}
velocityMult: 8
launchPoint: {fileID: 0}
launchPos: {x: 0, y: 0, z: 0}
projectile: {fileID: 0}
aimingMode: 0
--- !u!1 &1695677383
GameObject:
m_ObjectHideFlags: 0
@ -570,6 +620,8 @@ GameObject:
- component: {fileID: 1695677386}
- component: {fileID: 1695677385}
- component: {fileID: 1695677384}
- component: {fileID: 1695677387}
- component: {fileID: 1695677388}
m_Layer: 0
m_Name: _MainCamera
m_TagString: MainCamera
@ -643,6 +695,40 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1695677387
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695677383}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 351e76b062f02288684a52e9520a2f4f, type: 3}
m_Name:
m_EditorClassIdentifier:
easing: 0.05
minXY: {x: 0, y: 0}
camZ: 0
--- !u!114 &1695677388
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1695677383}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ce3134b55d3319a479f8fc97faf1fd0a, type: 3}
m_Name:
m_EditorClassIdentifier:
numClouds: 40
cloudPrefab: {fileID: 8854510988329328583, guid: 04469ca463c6fae3b8e0e6234db36784, type: 3}
cloudPosMin: {x: -50, y: -5, z: 10}
cloudPosMax: {x: 150, y: 100, z: 10}
cloudScaleMin: 1
cloudScaleMax: 3
cloudSpeedMult: 0.5
--- !u!1 &1835181602
GameObject:
m_ObjectHideFlags: 0
@ -733,67 +819,10 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1835181602}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -10, z: 0}
m_LocalScale: {x: 100, y: 1, z: 4}
m_LocalPosition: {x: 100, y: -10, z: 0}
m_LocalScale: {x: 400, y: 1, z: 4}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &7364702671896846279
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7364702671587352604, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_Name
value: Projectile
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7364702671587352615, guid: bdf63a487fce38097b5e77b912360559, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bdf63a487fce38097b5e77b912360559, type: 3}

59
Assets/Scripts/Cloud.cs Normal file
View File

@ -0,0 +1,59 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cloud : MonoBehaviour
{
[Header("Set in Inspector")]
public GameObject cloudSphere;
public int numSpheresMin = 6;
public int numSpheresMax = 10;
public Vector3 sphereOffsetScale = new Vector3(5,2,1);
public Vector2 sphereScaleRangeX = new Vector2(4,8);
public Vector2 sphereScaleRangeY = new Vector2(3,4);
public Vector2 sphereScaleRangeZ = new Vector2(2,4);
public float scaleYMin = 2f;
private List<GameObject> spheres;
// Start is called before the first frame update
void Start()
{
spheres = new List<GameObject>();
int num = Random.Range(numSpheresMin, numSpheresMax);
for (int i = 0; i < num; i++) {
GameObject sp = Instantiate<GameObject>(cloudSphere);
spheres.Add(sp);
Transform spTrans = sp.transform;
spTrans.SetParent(this.transform);
// Randomly assign a position
Vector3 offset = Random.insideUnitSphere;
offset.x *= sphereOffsetScale.x;
offset.y *= sphereOffsetScale.y;
offset.z *= sphereOffsetScale.z;
spTrans.localPosition = offset;
// Randomly assign scale
Vector3 scale = Vector3.one;
scale.x = Random.Range(sphereScaleRangeX.x, sphereScaleRangeX.y);
scale.y = Random.Range(sphereScaleRangeY.x, sphereScaleRangeY.y);
scale.z = Random.Range(sphereScaleRangeZ.x, sphereScaleRangeZ.y);
// Adjust y scale by x distance from core
scale.y *= 1 - (Mathf.Abs(offset.x) / sphereOffsetScale.x);
scale.y = Mathf.Max(scale.y, scaleYMin);
spTrans.localScale = scale;
}
}
// Update is called once per frame
void Update()
{
//if (Input.GetKeyDown(KeyCode.Space)) {
// Restart();
//}
}
void Restart() {
// Clear out old spheres
foreach (GameObject sp in spheres) {
Destroy(sp);
}
Start();
}
}

View File

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

View File

@ -0,0 +1,65 @@
using UnityEngine;
using System.Collections;
public class CloudCrafter : MonoBehaviour
{
[Header("Set in Inspector")]
public int numClouds = 40; // The # of clouds to make
public GameObject cloudPrefab ; // The prefab for the clouds
public Vector3 cloudPosMin = new Vector3(-50,-5,10);
public Vector3 cloudPosMax = new Vector3(150,100,10);
public float cloudScaleMin = 1; // Max scale of each cloud
public float cloudScaleMax = 3; // Max scale of each cloud
public float cloudSpeedMult = 0.5f;
private GameObject[] cloudInstances;
void Awake() {
// Make an array large enough to hold all the Cloud instances
cloudInstances = new GameObject[numClouds];
// Find the CloudAnchor parent GameObject
GameObject anchor = GameObject.Find("CloudAnchor");
// Iterate through and make Clouds
GameObject cloud;
for (int i = 0; i < numClouds; i++) {
// Make an instance of cloudPrefab
cloud = Instantiate<GameObject>(cloudPrefab);
// Position cloud
Vector3 cPos = Vector3.zero;
cPos.x = Random.Range(cloudPosMin.x, cloudPosMax.x);
cPos.y = Random.Range(cloudPosMin.y, cloudPosMax.y);
// Scale cloud
float scaleU = Random.value;
float scaleVal = Mathf.Lerp(cloudScaleMin, cloudScaleMax, scaleU);
// Smaller clouds (with smaller scaleU) should be nearer the ground
cPos.y = Mathf.Lerp(cloudPosMin.y, cPos.y, scaleU);
// Smaller cloud should be further away
cPos.z = 100 - 90 * scaleU;
// Apply these transforms to the cloud
cloud.transform.position = cPos;
cloud.transform.localScale = Vector3.one * scaleVal;
// Make cloud a child of the anchor
cloud.transform.SetParent(anchor.transform);
// Add the cloud to cloudInstances
cloudInstances[i] = cloud;
}
}
// Update is called once per frame
void Update()
{
// Iterate over each cloud that was create
foreach (GameObject cloud in cloudInstances) {
// Get the cloud scale and position
float scaleVal = cloud.transform.localScale.x;
Vector3 cPos = cloud.transform.position;
// Move larger clouds faster
cPos.x -= scaleVal * Time.deltaTime * cloudSpeedMult;
// If a cloud has moved too far to the left...
if (cPos.x <= cloudPosMin.x) {
// Move it to the far right
cPos.x = cloudPosMax.x;
}
// Apply the new position to cloud
cloud.transform.position = cPos;
}
}
}

View File

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

View File

@ -0,0 +1,32 @@
using UnityEngine;
using System.Collections;
public class FollowCam : MonoBehaviour
{
static public GameObject POI; // The static point of interest
[Header("Set in Inspector")]
public float easing = 0.05f;
public Vector2 minXY = Vector2.zero;
[Header("Set Dynamically")]
public float camZ; // The desired Z pos of the camera
void Awake() {
camZ = this.transform.position.z;
}
void FixedUpdate() {
// if there's only one line following an if, it doesn't need braces
if (POI == null) return; // return if there is no poi
// Get the position of the poi
Vector3 destination = POI.transform.position;
// Limit the X & Y to minimum values
destination.x = Mathf.Max(minXY.x, destination.x);
destination.y = Mathf.Max(minXY.y, destination.y);
// Interpolate from the current Camera position toward destination
destination = Vector3.Lerp(transform.position, destination, easing);
// Force destination.z to be camZ to keep the camera far enough away
destination.z = camZ;
// Set the camera to the destination
transform.position = destination;
// Set the orthographicSize of the Camera to keep Ground in view
Camera.main.orthographicSize = destination.y + 10;
}
}

View File

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

View File

@ -3,10 +3,69 @@ using System.Collections;
public class Slingshot : MonoBehaviour
{
// fields set in the Unity Inspector pane
[Header("Set in Inspector")]
public GameObject prefabProjectile;
public float velocityMult = 8f;
// fields set dynamically
[Header("Set Dynamically")]
public GameObject launchPoint;
public Vector3 launchPos;
public GameObject projectile;
public bool aimingMode;
private Rigidbody projectileRigidbody;
void Awake() {
Transform launchPointTrans = transform.Find("LaunchPoint");
launchPoint = launchPointTrans.gameObject;
launchPoint.SetActive(false);
launchPos = launchPointTrans.position;
}
void OnMouseEnter() {
print("Slingshot:OnMouseEnter()");
//print("Slingshot:OnMouseEnter()");
launchPoint.SetActive(true);
}
void OnMouseExit() {
print("Slingshot:OnMouseExit()");
//print("Slingshot:OnMouseExit()");
launchPoint.SetActive(false);
}
void OnMouseDown() {
// The player has pressed the mouse button while over Slingshot
aimingMode = true;
// Instantiate a projectile
projectile = Instantiate(prefabProjectile) as GameObject;
// Start it at the launchPoint
projectile.transform.position = launchPos;
// Set it to isKinematic for now
projectile.GetComponent<Rigidbody>().isKinematic = true;
// Set it to isKinematic for now
projectileRigidbody = projectile.GetComponent<Rigidbody>();
projectileRigidbody.isKinematic = true;
}
void Update() {
// If Slingshot is not in aimingMode, don't run this code
if (!aimingMode) return;
// Get the current mouse position in 2D screen coordinates
Vector3 mousePos2D = Input.mousePosition;
mousePos2D.z = -Camera.main.transform.position.z;
Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D);
// Find the delta from the launchPos to the mousePos3D
Vector3 mouseDelta = mousePos3D - launchPos;
// Limit mouseDelta to the radius of the Slingshot SphereCollider
float maxMagnitude = this.GetComponent<SphereCollider>().radius;
if (mouseDelta.magnitude > maxMagnitude) {
mouseDelta.Normalize();
mouseDelta *= maxMagnitude;
}
// Move the projectile to this new position
Vector3 projPos = launchPos + mouseDelta;
projectile.transform.position = projPos;
if (Input.GetMouseButtonUp(0)) {
// The mouse has been released
aimingMode = false;
projectileRigidbody.isKinematic = false;
projectileRigidbody.velocity = -mouseDelta * velocityMult;
FollowCam.POI = projectile;
projectile = null;
}
}
}