Rocket is created and flies in correct direction

This commit is contained in:
alsarazin 2015-11-09 17:09:37 -05:00
parent 9b2cd431a5
commit 9a0ee95db0
10 changed files with 293 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

@ -0,0 +1,67 @@
fileFormatVersion: 2
guid: 79e3562d4e1047c45a1cc07e1a7afd28
timeCreated: 1447087586
licenseType: Free
TextureImporter:
fileIDToRecycleName:
21300000: missile_1
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: 16
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 1
textureType: 8
buildTargetSettings: []
spriteSheet:
sprites:
- name: missile_1
rect:
serializedVersion: 2
x: 254
y: 473
width: 24
height: 10
alignment: 0
pivot: {x: .5, y: .5}
border: {x: 0, y: 0, z: 0, w: 0}
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,6 +13,7 @@ GameObject:
- 61: {fileID: 6183734}
- 114: {fileID: 11477144}
- 50: {fileID: 5006852}
- 114: {fileID: 11437552}
m_Layer: 8
m_Name: Player
m_TagString: Untagged
@ -106,6 +107,20 @@ Animator:
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
--- !u!114 &11437552
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 101678}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2197f504ed5ef864b9bc03da81a8f4fb, type: 3}
m_Name:
m_EditorClassIdentifier:
rocket: {fileID: 5027078, guid: 1cf24e915b357664f94ba440a1d1ec1a, type: 2}
rocket_position_offset: {x: .100000001, y: 0, z: 0}
speed: 3
--- !u!114 &11477144
MonoBehaviour:
m_ObjectHideFlags: 1
@ -156,7 +171,19 @@ Prefab:
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_Modifications:
- target: {fileID: 0}
propertyPath: rocket
value:
objectReference: {fileID: 5027078, guid: 1cf24e915b357664f94ba440a1d1ec1a, type: 2}
- target: {fileID: 0}
propertyPath: speed
value: 3
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: rocket_position_offset.x
value: .100000001
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 101678}

View File

@ -0,0 +1,104 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &141294
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 4: {fileID: 421606}
- 212: {fileID: 21212352}
- 50: {fileID: 5027078}
- 114: {fileID: 11450384}
m_Layer: 0
m_Name: rocket
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &421606
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 141294}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: .651942611, y: .117486805, z: 0}
m_LocalScale: {x: .5, y: .5, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!50 &5027078
Rigidbody2D:
serializedVersion: 2
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 141294}
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: .0500000007
m_GravityScale: 1
m_IsKinematic: 1
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!114 &11450384
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 141294}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0523305ab193c9b4dbcf3a14bd1fd1ae, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!212 &21212352
SpriteRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 141294}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000e000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 0
m_ReflectionProbeUsage: 0
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_ImportantGI: 0
m_AutoUVMaxDistance: .5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 79e3562d4e1047c45a1cc07e1a7afd28, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 0}
propertyPath: m_IsKinematic
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: speed
value: 5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 141294}
m_IsPrefabParent: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1cf24e915b357664f94ba440a1d1ec1a
timeCreated: 1447087667
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

14
Assets/RocketBehaviour.cs Normal file
View File

@ -0,0 +1,14 @@
using UnityEngine;
using System.Collections;
public class RocketBehaviour : MonoBehaviour {
void Start ()
{
}
//TODO : kill the rocket when exiting camera view
void Update ()
{
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0523305ab193c9b4dbcf3a14bd1fd1ae
timeCreated: 1447089423
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,42 @@
using UnityEngine;
using System.Collections;
public class FireScript : MonoBehaviour {
public Rigidbody2D rocket;
public Vector3 rocket_position_offset;
public float speed = 10f;
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
{
FireRocket(gameObject.GetComponent<PlayerBehavior>().GetFacingRight());
}
}
void FireRocket(bool facingRight)
{
//Instantiate new rocket
Rigidbody2D rocketClone = (Rigidbody2D)Instantiate(rocket, transform.position, Quaternion.identity);
if (!facingRight)
{
//Flip the rocket
Vector3 scale = rocketClone.gameObject.transform.localScale;
scale.x *= -1;
rocketClone.gameObject.transform.localScale = scale;
//Substract the offset
rocketClone.gameObject.transform.position -= rocket_position_offset;
}
else
{
//Add the offset
rocketClone.gameObject.transform.position += rocket_position_offset;
}
//Make the rocket move
rocketClone.velocity = new Vector2(speed * transform.localScale.x, 0);
}
}

View File

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 2197f504ed5ef864b9bc03da81a8f4fb
timeCreated: 1447090112
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences:
- rocket: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -47,6 +47,11 @@ public class PlayerBehavior : MonoBehaviour {
anim.SetFloat("Speed", Mathf.Abs(xMove));
}
public bool GetFacingRight()
{
return facingRight;
}
// ----- Private function(s)
private void flip()
{