Search Unity

Commented code still runs

Discussion in 'Scripting' started by IchBinJager, Jul 29, 2017.

  1. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    Something very bizarre is happening, I tried commenting out code for an enemy class and they still move. Why is this happening?
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Something else is probably happening, causing it to not compile. Check your error log carefully. Some errors may look like runtime errors but are actually from the compilation phase, and it lets you run the project anyway. I've been hit by that a couple of times this week.
     
  3. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    All I get are warning but it still happens.
     
  4. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Is it small enough that you can show the code here?
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Code would help. Errors/warnings would help. Is this when playing in the editor or in a standalone build? You haven't provided anything for anyone to even speculate on.
     
  6. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    This is my code for grunt.cs and enemy.cs

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Grunt : Enemy {
    7.  
    8.  
    9.    static Player Active_Ply;
    10.    static int World_LMask = 1 << 0;
    11.    
    12.    float Last_Shot;
    13.    
    14.    public GameObject Projectile_Obj;
    15.    
    16.    public Grunt()
    17.    {
    18.        Health = 30;
    19.        Move_Speed = 2;
    20.        Attack_Delay = 1;
    21.    }
    22.    
    23.    Transform Head;
    24.    Rigidbody2D RBody;
    25.    
    26.    // Aims only where the player currently is. No leading.
    27.  
    28.    // Use this for initialization
    29.    void Start () {
    30.        
    31.        Head = transform.GetChild(0);
    32.        RBody = GetComponent<Rigidbody2D>();
    33.        
    34.        if ( Active_Ply == null )
    35.        {
    36.            Active_Ply = GameObject.FindWithTag("Player").GetComponent<Player>();
    37.        }
    38.    }
    39.    
    40.    void FixedUpdate()
    41.    {
    42.        if ( Time.timeScale == 0 )
    43.        {
    44.            return;
    45.        }
    46.        
    47.        if ( Active_Ply == null )
    48.        {
    49.            Active_Ply = GameObject.FindWithTag("Player").GetComponent<Player>();
    50.        }
    51.        
    52.        
    53.        RaycastHit2D Sight_Check = Physics2D.Linecast( transform.position, Active_Ply.transform.position, World_LMask );
    54.        
    55.        if ( Sight_Check.collider != null )
    56.        {
    57.            return;
    58.        }
    59.        
    60.        transform.up = (transform.position - Active_Ply.transform.position).normalized;
    61.        
    62.        
    63.        if ( Last_Attack + Attack_Delay <= Time.time )
    64.        {
    65.            Last_Attack = Time.time;
    66.            GameObject New_Bullet = Instantiate ( Projectile_Obj ); New_Bullet.transform.position = transform.position;
    67.            New_Bullet.transform.up = -Head.transform.up;
    68.        }
    69.        
    70.        if ( Vector3.Distance(transform.position, Active_Ply.transform.position) > 2 )
    71.        {
    72.            //RBody.AddForce( -transform.up * 2 );
    73.            //RBody.velocity = new Vector2(-transform.up.x, -transform.up.y) * 2;
    74.            
    75.            
    76.            Debug.Log(RBody.velocity);
    77.            return;
    78.            
    79.        }
    80.        
    81.        
    82.        
    83.    }
    84. }
    85.  
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Enemy : MonoBehaviour {
    7.  
    8.    protected int Health ;
    9.    protected float Move_Speed, Last_Attack, Attack_Delay;
    10.    
    11.    
    12.    public float last_damaged;
    13.  
    14.    SpriteRenderer Sprite;
    15.    
    16.    public virtual void Stop_Flash()
    17.    {
    18.        GetComponent<SpriteRenderer>().color = Color.white;
    19.    }
    20.    
    21.    public virtual void Damaged( int dmg_amt )
    22.    {
    23.        
    24.        Health -= dmg_amt;
    25.        if ( Health == 0 )
    26.        {
    27.            Destroy(gameObject);
    28.        }
    29.        
    30.        GetComponent<SpriteRenderer>().color = Color.red;
    31.        Invoke("Stop_Flash",.1f);
    32.        
    33.    }
    34.  
    35.    
    36.    public Enemy()
    37.    {
    38.        
    39.    }
    40.    
    41.    // Use this for initialization
    42.    void Start () {
    43.        gameObject.layer = 11;
    44.        Sprite = GetComponent<SpriteRenderer>();
    45.    }
    46.    
    47.    // Update is called once per frame
    48.    void Update () {
    49.        
    50.    }
    51. }
    52.