#Protected Override Void Function Won't Call After Adding Void Update Loop

1 messages · Page 1 of 1 (latest)

latent ember
#

I've added an update loop after a protected overrided void function and it won't call anymore. It derives from another script (not MonoBehaviour). Help is much appreciated tysm 🙂

lavish pendantBOT
#

It's hard to answer a programming question without code

Resolving a bug is almost impossible when the question doesn't include any of the buggy code. In order to help fix the problem, answerers are going to have to see what the code is.
Source: https://idownvotedbecau.se/nocode

Please isolate the problematic code and send it as a codeblock. If you don't know how to send a codeblock, type []cb

latent ember
#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class basicTower : Tower
{
public Transform Pivot;
public Transform Barrel;
public GameObject Bullet;

private void Update()
{
    if (towerMenu != null)
    {
        if (shopManagerScript != null)
        {
            newCost = shopManagerScript.basicTowerCost + 1;
        }
        towerMenu.upgradeCost = newCost;
    }
    if (upgradeTier == 1 && alrUpgraded == false)
    {
        Debug.Log("TIER 1 Upgrade");
        alrUpgraded = true;
    }
    if (upgradeTier == 2 && alrUpgraded == false)
    {
        Debug.Log("TIER 2 Upgrade");
        alrUpgraded = true;
    }
    if (upgradeTier == 3 && alrUpgraded == false)
    {
        Debug.Log("TIER 3 Upgrade");
        alrUpgraded = true;
    }
    if (upgradeTier == 4 && alrUpgraded == false)
    {
        Debug.Log("TIER 4 Upgrade");
        alrUpgraded = true;
    }
    if (upgradeTier == 5 && alrUpgraded == false)
    {
        Debug.Log("TIER 5 Upgrade");
        alrUpgraded = true;
    }
}
#

private void FixedUpdate()
{
if (towerMenu != null)
{
shopManagerScript = GameObject.Find("Shop_Manager").GetComponent<shopManager>();
if (towerMenu.upgrade && upgradeTier < upgradeLevels)
{

            towerMenu.upgradeCost = newCost;

            //Debug.Log("Upgrade");
            if (moneyManager.Money.currentPlayerMoney >= newCost)
            {
                upgradeTier++;
                moneyManager.Money.currentPlayerMoney = moneyManager.Money.currentPlayerMoney - newCost;
            }

            alrUpgraded = false;
            //Debug.Log(upgradeTier);
            towerMenu.upgrade = false;
        }
    }
}

protected override void Shoot() //not activating but why?
{
    base.Shoot();

    GameObject New_Bullet = Instantiate(Bullet,Barrel.position,Pivot.rotation);
}

}

stable finch
latent ember
#

sorry

stable finch
#

That's not a codeblock

lavish pendantBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks like so:

```cs
// your code here
```

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

latent ember
#
    {
        base.Shoot();

        GameObject New_Bullet = Instantiate(Bullet,Barrel.position,Pivot.rotation);
    }```
stable finch
#

Where are you calling this method

latent ember
#

in a script deriving from another script under void update

#

not inside void update

stable finch
#

what

#

show the code where you're calling Shoot

latent ember
stable finch
#

That's not calling it

latent ember
#

it calls normally when i run the script

#

because the script it derives from automatically calls it

stable finch
#

Where

latent ember
#

the script that the problematic one derives from

#

the shoot(); is overwritten

stable finch
#

Are you sure the if statement is executing?

latent ember
#

it executes when i remove the fixed update loop in the problematic script

stable finch
#

Well if Shoot is not being called, there are four possibilities

  1. This behaviour isn't on any object
  2. The object is disabled (ergo Update will not run)
  3. Next_Time_To_Shoot is not low enough, meaning Time.time will never be greater than or equal to it
  4. Current_Target is null
latent ember
#

ty for ur help i will test out each of the 4

#

have a nice day