First of all, welcome to the community and Unity. Now I'll try to explain this as much as I can. There are lots of ways to do that, but I think what you are asking is not about the situation you are experiencing but you would like to know the proper way. But first let me offer you a simple solution to your problem:
Assign a reference to Ball.cs of Paddle.cs and modify it when you need it:
public Paddle paddle; // Assign this public reference on inspector
void OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "Roof" && hitTop == false)
{
hitTop = true;
Vector3 dir = col.contacts[0].point - transform.position;
dir = -dir.normalized;
GetComponent ().AddForce (dir * speedUp);
paddle.transform.localScale -= new Vector3(1.5f, 0, 0);
}
}
But as you've guessed this is kind of wrong. Ball should not know what Paddle is. Yet it shouldn't even modify Paddle in any way. So a better way to do this is to have a Manager object which holds reference to the Paddle and Ball and control the game logic. This is just fine for small projects like this one, but if the project gets bigger, this will be a problem too. If all your logic is handled in your GameManager, there is a big chance of breaking other thing when you change something that is related to GameManager.
A better way of doing this is perhaps with events. I don't know your knowledge of programming but if you just started, I recommend you not to look at these just yet. Try to make games and understand how things work, and think about how they should work, and constantly challenge your mind to how you can do the same thing in a better way.
[Here is a link if you would like to learn about events][1]. If you don't understand what's going on, as I've said earlier try to continue with learning basic/intermediate stuff until you feel the need of advanced stuff like this. Also, [Check this link][2] if you like to learn what you will need to learn in the future.
Good luck with your studies.
[1]: http://rahuldhammy-shares.blogspot.com.tr/2012/02/delegates-events-c.html
[2]: http://answers.unity3d.com/questions/1354956/what-are-the-best-practices-of-designing-code-arch.html
↧