Commit 756045ce authored by Parsa Rahmaty's avatar Parsa Rahmaty

Cannon shooting mechanics updated

parent 664f7575
......@@ -495,7 +495,7 @@ GameObject:
- component: {fileID: 1827272340}
m_Layer: 0
m_Name: Cannon
m_TagString: Untagged
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -530,7 +530,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
projectile: {fileID: 3972782314967972539, guid: 2237038f8f5183148913886475229ea4,
type: 3}
shootingDelay: 50
shootingDelay: 0.18
cannonColliders:
- {fileID: 1389915129}
- {fileID: 1384577412}
......@@ -5,10 +5,10 @@ using UnityEngine;
public class CannonControls : MonoBehaviour
{
[SerializeField] private GameObject projectile;
[SerializeField] private int shootingDelay;
[SerializeField] private float shootingDelay;
[SerializeField] private Collider[] cannonColliders;
private int delay;
private int framesLeftToShoot = 0; // the number of frames passed since last shot
private float delay;
private float framesLeftToShoot = 0f; // the number of frames passed since last shot
void Start()
{
......@@ -19,8 +19,7 @@ public class CannonControls : MonoBehaviour
{
if(Input.GetKey(KeyCode.Space))
{
Debug.Log(delay);
if (framesLeftToShoot == 0)
if (framesLeftToShoot <= 0f)
{
// start shooting cannonballs
GameObject childObject = Instantiate(projectile) as GameObject;
......@@ -29,19 +28,19 @@ public class CannonControls : MonoBehaviour
childObject.transform.parent = gameObject.transform;
childObject.transform.localPosition = new Vector3(0, 0, 0);
framesLeftToShoot = delay - 1;
if(delay > (shootingDelay * 1) / 2)
delay--;
if(delay > (shootingDelay * 1f) / 2f)
delay *= 0.95f;
framesLeftToShoot = delay;
}
else
{
framesLeftToShoot--;
framesLeftToShoot -= Time.deltaTime;
}
}
if (Input.GetKeyUp(KeyCode.Space))
{
delay = shootingDelay;
framesLeftToShoot = 0;
framesLeftToShoot = 0f;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment