r/UnityHelp • u/Assailent • 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
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);