I am a total beginner to unity and C# and am trying to make a very simple game.
I am trying to figure out the best, most efficient way of scripting the following behavior:
A shape on the 2d plane such as a circle (sphere) or a cube (square), that can be stretched (have the scale changed) by the player by clicking on it and dragging away from the centre or shrinking it by dragging towards the centre. Does anyone have any experience doing this?
Hi @fivegrandpint “I am a total beginner to unity and C#” … “I am trying to figure out the best, most efficient way”
A combination that is pretty much not going to happen and what would be the point to even think this, if you don’t even know where to start from? You should learn the basics first like the rest of us…
I haven’t done exactly this kind of thing, but in short this is what I would do;
Get the center point of the object to be scaled.
Get the mouse click position in screen space. Convert mouse screen space position to world space.
Calculate distance between these two points.
If current distance is shorter than the distance in the previous frame, you will scale down the shape.
If current distance is longer than the distance in the previous frame, you will scale up the shape.
You can google each thing separately, and that way you’ll get started!
Hi yeah I just meant im looking for the best way to do it. I have been working my way through a book on C# basics, it is “Learning C# by Developing games in Unity5.x” by Greg Lukosek and made a simple game but still struggling with this. I found the best way to get the centre according to this site https://answers.unity.com/questions/361518/how-to-get-center-of-an-object.html is to use getcomponent.transform.position but every time I try to implement this it doesnt seem to recognise it and i get these errors:
Error CS0119 ‘Component.GetComponent(Type)’ is a method, which is not valid in the given context
Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement