Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Error CS0029 please help me

Discussion in 'Scripting' started by JordanRL, May 1, 2013.

  1. JordanRL

    JordanRL

    Joined:
    Apr 30, 2013
    Posts:
    10
    Hi,

    Im getting a random error for an unknown reason. the compiler isn't showing me were the error is but I have two float statements. it says "cannot implicitly convert type 'float' to 'bool' ".

    using UnityEngine;
    using System.Collections;

    public class EnemyAttack : MonoBehaviour {
    public GameObject target;
    public float attackTimer;
    public float coolDown;

    // Use this for initialization
    void Start () {
    attackTimer = 0;
    coolDown = 2.0f;
    }

    // Update is called once per frame
    void Update () {
    if(attackTimer > 0)
    attackTimer -= Time.deltaTime;

    if(attackTimer < 0)
    attackTimer = 0;

    if(attackTimer = 0) {
    Attack();
    attackTimer = coolDown;
    }

    }

    I honestly dont see any errors here...
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Code (csharp):
    1.  
    2. if(attackTimer = 0) {
    3. Attack();
    4. attackTimer = coolDown;
    5. }  
    6.  
    7.  
    should be...

    Code (csharp):
    1.  
    2.  
    3. if(attackTimer == 0) {
    4. Attack();
    5. attackTimer = coolDown;
    6. }  
    7.  
    8.  
     
  3. JordanRL

    JordanRL

    Joined:
    Apr 30, 2013
    Posts:
    10
    thanks for the fast response :) and one equals mistake grr XD
     
  4. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    In the future, please format the code using
    Code (csharp):
    1.  tags.