If code works, a good code?

Hey, i´m on section 152 in that Complete C# Developer course 3d. There I should make my Tower placeable. Now i did it and asks me:" If my code works but @Ben takes another way. Wich code should i take?"

Here´s my code

 private void OnMouseOver()
    {
        PathFinder pathFinder = GetComponentInParent<PathFinder>();
        if(Input.GetMouseButton(0))
        {
            if(isPlaceable == true && pathFinder.towerCount < maxTower)
            {
                if (pathFinder.towerCount < maxTower)
                { 
                    Instantiate(tower,transform.position,Quaternion.identity);
                    isPlaceable = false;
                    pathFinder.towerCount ++;
                }
            }

            else 
            { 
                Debug.Log("Here is nothing to place"); 
            }
           
        }
    }

It’s really up to you, I think if your code is behaving how you intended then it’s good and doesn’t need to be changed.

Privacy & Terms