Destroyed the rockets when not visible/colliding

This commit is contained in:
alsarazin 2015-11-10 19:55:24 -05:00
parent ad2b5d72a6
commit ff569b86fe
4 changed files with 38 additions and 21 deletions

View File

@ -11,6 +11,7 @@ GameObject:
- 212: {fileID: 21212352} - 212: {fileID: 21212352}
- 50: {fileID: 5027078} - 50: {fileID: 5027078}
- 114: {fileID: 11450384} - 114: {fileID: 11450384}
- 61: {fileID: 6184698}
m_Layer: 0 m_Layer: 0
m_Name: rocket m_Name: rocket
m_TagString: Untagged m_TagString: Untagged
@ -40,12 +41,25 @@ Rigidbody2D:
m_Mass: 1 m_Mass: 1
m_LinearDrag: 0 m_LinearDrag: 0
m_AngularDrag: .0500000007 m_AngularDrag: .0500000007
m_GravityScale: 1 m_GravityScale: 0
m_IsKinematic: 1 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 0
m_SleepingMode: 1 m_SleepingMode: 1
m_CollisionDetection: 0 m_CollisionDetection: 0
m_Constraints: 0 m_Constraints: 0
--- !u!61 &6184698
BoxCollider2D:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 141294}
m_Enabled: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Size: {x: .239999995, y: .100000001}
--- !u!114 &11450384 --- !u!114 &11450384
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@ -92,12 +106,16 @@ Prefab:
m_Modifications: m_Modifications:
- target: {fileID: 0} - target: {fileID: 0}
propertyPath: m_IsKinematic propertyPath: m_IsKinematic
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 0} - target: {fileID: 0}
propertyPath: speed propertyPath: speed
value: 5 value: 5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_GravityScale
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 0} m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 141294} m_RootGameObject: {fileID: 141294}

View File

@ -3,12 +3,22 @@ using System.Collections;
public class RocketBehaviour : MonoBehaviour { public class RocketBehaviour : MonoBehaviour {
void Start () private bool isAPlayerRocket;
//Destroys the rocket when no longer visible
void OnBecameInvisible()
{ {
Destroy(gameObject);
}
//Destroys the rocket when it hits something (except Player when its his rocket)
void OnCollisionEnter2D(Collision2D collision)
{
if(!isAPlayerRocket || collision.gameObject.tag != "Player")
Destroy(gameObject);
} }
//TODO : kill the rocket when exiting camera view public void SetProperty(bool playerRocket)
void Update ()
{ {
isAPlayerRocket = playerRocket;
} }
} }

View File

@ -21,6 +21,9 @@ public class FireScript : MonoBehaviour {
//Instantiate new rocket //Instantiate new rocket
Rigidbody2D rocketClone = (Rigidbody2D)Instantiate(rocket, transform.position, Quaternion.identity); Rigidbody2D rocketClone = (Rigidbody2D)Instantiate(rocket, transform.position, Quaternion.identity);
//Sets rocket to be the player's
rocketClone.gameObject.GetComponent<RocketBehaviour>().SetProperty(true);
if (!facingRight) if (!facingRight)
{ {
//Flip the rocket //Flip the rocket

View File

@ -8,7 +8,6 @@ PlayerSettings:
defaultScreenOrientation: 4 defaultScreenOrientation: 4
targetDevice: 2 targetDevice: 2
targetResolution: 0 targetResolution: 0
useOnDemandResources: 0
accelerometerFrequency: 60 accelerometerFrequency: 60
companyName: DefaultCompany companyName: DefaultCompany
productName: Laboratoire_2_Equipe_2 productName: Laboratoire_2_Equipe_2
@ -29,7 +28,6 @@ PlayerSettings:
androidShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1
iosAppInBackgroundBehavior: 0 iosAppInBackgroundBehavior: 0
displayResolutionDialog: 1 displayResolutionDialog: 1
iosAllowHTTPDownload: 1
allowedAutorotateToPortrait: 1 allowedAutorotateToPortrait: 1
allowedAutorotateToPortraitUpsideDown: 1 allowedAutorotateToPortraitUpsideDown: 1
allowedAutorotateToLandscapeRight: 1 allowedAutorotateToLandscapeRight: 1
@ -137,15 +135,6 @@ PlayerSettings:
iOSLaunchScreenFillPct: 100 iOSLaunchScreenFillPct: 100
iOSLaunchScreenSize: 100 iOSLaunchScreenSize: 100
iOSLaunchScreenCustomXibPath: iOSLaunchScreenCustomXibPath:
iOSLaunchScreeniPadType: 0
iOSLaunchScreeniPadImage: {fileID: 0}
iOSLaunchScreeniPadBackgroundColor:
serializedVersion: 2
rgba: 0
iOSLaunchScreeniPadFillPct: 100
iOSLaunchScreeniPadSize: 100
iOSLaunchScreeniPadCustomXibPath:
iOSDeviceRequirements: []
AndroidTargetDevice: 0 AndroidTargetDevice: 0
AndroidSplashScreenScale: 0 AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0} androidSplashScreen: {fileID: 0}
@ -235,8 +224,6 @@ PlayerSettings:
ps4SdkOverride: ps4SdkOverride:
ps4BGMPath: ps4BGMPath:
ps4ShareFilePath: ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4NPtitleDatPath: ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir: ps4RemotePlayKeyMappingDir:
@ -258,7 +245,6 @@ PlayerSettings:
ps4attribMoveSupport: 0 ps4attribMoveSupport: 0
ps4attrib3DSupport: 0 ps4attrib3DSupport: 0
ps4attribShareSupport: 0 ps4attribShareSupport: 0
ps4IncludedModules: []
monoEnv: monoEnv:
psp2Splashimage: {fileID: 0} psp2Splashimage: {fileID: 0}
psp2NPTrophyPackPath: psp2NPTrophyPackPath: