Added bullet amount upgrade

This commit is contained in:
Soulaha Balde 2022-05-14 17:37:08 -04:00
parent 8594123f60
commit 338a670918
11 changed files with 1680 additions and 93 deletions

File diff suppressed because it is too large Load Diff

View File

@ -203,10 +203,11 @@ MonoBehaviour:
cannon: {fileID: 6969840675257017922}
projectile: {fileID: 5630905120393344806, guid: 70e77cdd333989d4193d3d85029d8cbe, type: 3}
lookDepth: 400
cannonForce: 1000
cannonForce: 100
fireRate: 0.5
fireTimer: 0
damage: 1
bullets: 1
--- !u!1 &6969840675949508920
GameObject:
m_ObjectHideFlags: 0

View File

@ -15,7 +15,7 @@ GameObject:
- component: {fileID: 1596552820235563576}
- component: {fileID: -5096460011673770898}
- component: {fileID: 8618525506095844415}
m_Layer: 0
m_Layer: 6
m_Name: Projectile
m_TagString: Untagged
m_Icon: {fileID: 0}

View File

@ -241,6 +241,10 @@ PrefabInstance:
propertyPath: m_Name
value: Canvas_UI
objectReference: {fileID: 0}
- target: {fileID: 7292790684055438790, guid: 1fbf5b38e74bdfe4185768d47372abe2, type: 3}
propertyPath: player
value:
objectReference: {fileID: 1407792871}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1fbf5b38e74bdfe4185768d47372abe2, type: 3}
--- !u!1 &1966667440

View File

@ -13,15 +13,18 @@ public class CannonScript : MonoBehaviour
[SerializeField] private float fireRate = 0.5f;
[SerializeField]private float fireTimer;
private bool firing = false;
[SerializeField]private float damage = 1f;
private Vector3 lookDir;
private Vector3[] offsets;
[SerializeField]private int bullets;
// Start is called before the first frame update
void Start()
{
lookDir = Vector3.zero;
offsets = new Vector3[] {new Vector3(-0.1f, 0), new Vector3(0.1f, 0), new Vector3(0, -0.1f), new Vector3(0, 0.1f)};
bullets = 1;
}
// Update is called once per frame
@ -30,9 +33,7 @@ public class CannonScript : MonoBehaviour
if(firing && !EventSystem.current.IsPointerOverGameObject()){
fireTimer += Time.deltaTime;
if(fireTimer >= fireRate){
GameObject proj = Instantiate(projectile, cannon.transform.position, cannon.transform.rotation);
proj.GetComponent<Projectile>().SetDamage(damage);
proj.GetComponent<Rigidbody>().AddForce(cannonForce * lookDir, ForceMode.Impulse);
Fire();
fireTimer = 0;
RaycastHit hit;
@ -54,6 +55,21 @@ public class CannonScript : MonoBehaviour
}
}
void Fire(){
GameObject proj = Instantiate(projectile, cannon.transform.position, cannon.transform.rotation);
proj.GetComponent<Projectile>().SetDamage(damage);
proj.GetComponent<Rigidbody>().AddForce(cannonForce * lookDir, ForceMode.Impulse);
if(bullets > 1){
//Pick random offset from lookDir
for (int i = 0; i < bullets-1; i++)
{
proj = Instantiate(projectile, cannon.transform.position, cannon.transform.rotation);
proj.GetComponent<Projectile>().SetDamage(damage);
proj.GetComponent<Rigidbody>().AddForce(cannonForce * (lookDir+offsets[i]), ForceMode.Impulse);
}
}
}
private Vector3 GetMouseWorldPosition(){
Vector3 screenPos = Mouse.current.position.ReadValue();
screenPos.z = lookDepth;
@ -95,4 +111,12 @@ public class CannonScript : MonoBehaviour
return damage;
}
public void SetBullets(int nBullets){
this.bullets = nBullets;
}
public int GetBullets(){
return bullets;
}
}

View File

@ -36,6 +36,10 @@ public class PlayerController : MonoBehaviour
cannon.SetDamage(upgrade.GetDamage());
}
public void UpgradeBullets(BulletsAmountUpgrade upgrade){
cannon.SetBullets(upgrade.GetBullets());
}
public float GetPoints(){
return points;
}

View File

@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletsAmountUpgrade : Upgrade
{
[SerializeField]private int[] amounts;
public BulletsAmountUpgrade(string name, float[] cost, int[] amounts){
this.cost = cost;
this.upgradeName = name;
this.amounts = amounts;
}
public void SetBullets(int[] nAmounts){
this.amounts = nAmounts;
}
public int GetBullets(){
return amounts[lvlUnlocked-1];
}
public override void Activate(){
if(base.UpgradeAttempt()){
player.UpgradeBullets(this);
}
}
}

View File

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

View File

@ -24,16 +24,14 @@ public abstract class Upgrade : MonoBehaviour
}
public void OnPointerEnter(){
if(EventSystem.current.IsPointerOverGameObject()){
if(lvlUnlocked < imgs.Length){
hoverObj.SetActive(true);
}
}
public void OnPointerExit(){
if(EventSystem.current.IsPointerOverGameObject()){
hoverObj.SetActive(false);
}
}
public float GetCost(){
return cost[lvlUnlocked];
}

View File

@ -7,6 +7,7 @@ PhysicsManager:
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2
m_DefaultMaxDepenetrationVelocity: 10
m_SleepThreshold: 0.005
m_DefaultContactOffset: 0.01
m_DefaultSolverIterations: 6
@ -17,7 +18,7 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0.1
m_ClothInterCollisionStiffness: 0.2
m_ContactsGeneration: 1
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1
m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 1
@ -32,5 +33,6 @@ PhysicsManager:
m_FrictionType: 0
m_EnableEnhancedDeterminism: 0
m_EnableUnifiedHeightmaps: 1
m_ImprovedPatchFriction: 0
m_SolverType: 0
m_DefaultMaxAngularSpeed: 50

View File

@ -12,7 +12,7 @@ TagManager:
-
- Water
- UI
-
- Projectile
-
-
-