Rocket firing, sprinting

This commit is contained in:
Norbi Peti 2020-11-06 21:20:17 +01:00
parent bbf6eb4ea5
commit 92f929fc2b
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
8 changed files with 174 additions and 7 deletions

View file

@ -57,7 +57,9 @@
<ItemGroup>
<Compile Include="Assets\Scripts\CameraController.cs" />
<Compile Include="Assets\Scripts\OwnCharacterController.cs" />
<Compile Include="Assets\Scripts\RocketScript.cs" />
<Compile Include="Assets\Scripts\Tiling.cs" />
<Compile Include="Assets\Scripts\WeaponFireController.cs" />
<Reference Include="UnityEngine">
<HintPath>/D/Unity/2019.4.13f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath>
</Reference>

View file

@ -12,13 +12,14 @@ GameObject:
- component: {fileID: 2084791786893166414}
- component: {fileID: 5991448782009560204}
- component: {fileID: 5192784953082789806}
- component: {fileID: 6419502325325086616}
m_Layer: 0
m_Name: Rocket
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &4070025166081053470
Transform:
m_ObjectHideFlags: 0
@ -98,12 +99,12 @@ Rigidbody2D:
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_GravityScale: 0.000001
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
m_Constraints: 4
--- !u!61 &5192784953082789806
BoxCollider2D:
m_ObjectHideFlags: 0
@ -130,3 +131,15 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 1, y: 0.27385223}
m_EdgeRadius: 0
--- !u!114 &6419502325325086616
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6006275050469676560}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f1e53fae3d02fe2069d2d22853bfd631, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -219,6 +219,36 @@ MonoBehaviour:
hasARightBuddy: 0
hasALeftBuddy: 0
reverseScale: 0
--- !u!1 &1043406433
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1043406434}
m_Layer: 0
m_Name: RocketPoint
m_TagString: Untagged
m_Icon: {fileID: 7148428337604731935, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1043406434
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1043406433}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.128, y: 0.015, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2053847422}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1351818047
GameObject:
m_ObjectHideFlags: 0
@ -315,7 +345,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 015fa5e06b5b140ee996a1d4f3c42f31, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 0.05
speed: 0.02
target: {fileID: 2053847422}
offset: {x: 0, y: 0, z: 0}
--- !u!1 &1372634516
@ -430,7 +460,7 @@ GameObject:
- component: {fileID: 1508769557}
m_Layer: 0
m_Name: Ground
m_TagString: Untagged
m_TagString: Ground
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@ -556,6 +586,7 @@ GameObject:
- component: {fileID: 2053847424}
- component: {fileID: 2053847423}
- component: {fileID: 2053847425}
- component: {fileID: 2053847426}
m_Layer: 0
m_Name: Character
m_TagString: Untagged
@ -622,9 +653,10 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2053847420}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -8.28, y: 2.75, z: 0}
m_LocalPosition: {x: -7.23, y: 2.57, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 1043406434}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -687,3 +719,17 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 216ec793de06a4ac7a9767782a179419, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2053847426
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2053847420}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f400b7976b98bc18866f672d33d506a, type: 3}
m_Name:
m_EditorClassIdentifier:
prefab: {fileID: 5991448782009560204, guid: 7debf3c35b28387fdbec1c1c9942afae, type: 3}
firePoint: {fileID: 1043406434}

View file

@ -29,6 +29,9 @@ public class OwnCharacterController : MonoBehaviour
scale.x *= -1;
tr.localScale = scale;
}
if (Input.GetButton("Fire3"))
input *= 10;
rb.AddForce(new Vector2(input * 5, 0));
if (Input.GetButtonDown("Jump") && IsOnGround())

View file

@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RocketScript : MonoBehaviour
{
private float _fired;
private Rigidbody2D _rb;
private bool _goingRight;
// Start is called before the first frame update
void Start()
{
_rb = GetComponent<Rigidbody2D>();
}
private void OnEnable()
{
_fired = Time.fixedTime;
_goingRight = transform.localScale.x > 0;
}
// Update is called once per frame
void FixedUpdate()
{
if(!gameObject.activeSelf) return;
if (Time.fixedTime - _fired > 3)
{
gameObject.SetActive(false);
_rb.velocity = Vector2.zero;
}
_rb.AddForce(new Vector2(_goingRight ? 10 : -10, 0));
}
}

View file

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

View file

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class WeaponFireController : MonoBehaviour
{
public Rigidbody2D prefab;
public Transform firePoint;
private List<Rigidbody2D> rockets = new List<Rigidbody2D>(10);
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 10; i++)
rockets.Add(Instantiate(prefab));
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
Rigidbody2D theRocket = null;
foreach (var rocket in rockets)
{
if (!rocket.gameObject.activeSelf)
{
theRocket = rocket;
break;
}
}
if (theRocket is null)
rockets.Add(theRocket = Instantiate(prefab));
var rocketTransform = theRocket.transform;
rocketTransform.position = firePoint.position;
var scale = rocketTransform.localScale;
if (transform.localScale.x * scale.x < 0)
scale.x *= -1;
rocketTransform.localScale = scale;
theRocket.gameObject.SetActive(true);
}
}
}

View file

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