r/UnityHelp • • Mar 28 '21

2D Scale

So I'm trying to make a game for a school project and its going to be a bullet hell, its top down yet I'm having issues with the Player Scaling System.

I'm trying to get my player to scale up when they press E so they can control their size (I will add down with Q later but for now I need this to work. I'm New to C# Please Help

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Scale : MonoBehaviour
{

    public float BaseSize;
    public Vector2 Rigidbody2D;
    float Size;
    public float PlusScale;
    // Start is called before the first frame update
    void Start()
    {
        Size = BaseSize;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.E))
        {
            transform.localScale += Vector2(PlusScale, PlusScale);
        }
    }
}
3 Upvotes

3 comments sorted by

2

u/Sharkytrs Mar 29 '21

is there an error?

also as far as I am aware, localScale is a vector3, even on a 2d game. If you don't need to scale by z just add it in anyway as a 0, try:

transform.localScale += Vector3(PlusScale, PlusScale,0);

1

u/Assailent Mar 29 '21

Will Try Mate
-Assailent

1

u/Assailent Mar 29 '21 edited Mar 29 '21

It says Non invocable member Vector3 Cannot be used like a method

Edit:
Works Completely fine i just didnt have new before vector3