Creating a start position for other Balls

Hey folks, I just trying to create a simple solution to make it so that balls other than the player initiated ball can be placed in a the scene and remain static before they are hit, Basically so they just sit there, much like the ball sticks to the paddle, just without the movement… I feel like this should be simple and am currently bashing my head against the keyboard trying to give the secondary ball I’ve created its own script with a serialized field of an empty game object named Timstart…Visual studio does not seem to like this. It wont allow me to create a serialized field of this game object… or various others from my game, Any help would be apreciated… Thanks all
Erik

Hi,

What is the version number of Visual Studio you are using Erik?

VS 17 community, but I found A wonderful little solution after sleeping

first…Assigned all active balls in the scene a tag of ‘Active’ or ‘Inactive’

then using this :

public class TimBallScript : MonoBehaviour {


    [SerializeField] bool ballActive;

    LoseCollider losecollider;
    


    // Use this for initialization
    public void Start () {

   
    gameObject.transform.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        ballActive = false;

    }

    public void OnCollisionEnter2D(Collision2D collision)
    {
        gameObject.transform.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
        ballActive = true;
        if(gameObject.tag == "Inactive")
        {
            losecollider = FindObjectOfType<LoseCollider>();
            losecollider.CountBalls();
            gameObject.tag = "Active";
        }
    }

    // Update is called once per frame
    void Update () {
		
  
	}
}

And this

public class BallCounter : MonoBehaviour
{


    LoseCollider losecollider;

    // Use this for initialization

    private void Start()
    {
        if (gameObject.tag == "Active")
        {
            losecollider = FindObjectOfType<LoseCollider>();
            losecollider.CountBalls();
        }
    }
    private void Update()
    {
      
    }
}

in conjunction with our other scripts… I got it to work… fully!!! the scripts counts only the active balls and logs them as they are made active… only when there are no balls in play game there be a game over trigger…

And yeah for some reason I feel like the rigidbody2d.bodytype code should be shorter but for some reason after a thousand tries… and some sleep this worked…
Cheers,
Erik

1 Like

Privacy & Terms