using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Size_Changer : MonoBehaviour {
// Update is called once per frame
void FixedUpdate () {
if ((Input.GetKey ("space")) && (NotSURE) == Vector3(20, 20, 1))
transform.localScale += new Vector3(0.1F, 0.1F, 0);
}
}
The code will let me change the size of an object but it will keep going up even when it fills the whole screen and i would like to set a max size for the object where it cant be any bigger then can anyone help me.
@Dalecn You will need to compare the magnitude of you local scale value to a maximun localscale value, but you cant compare vector3 just like that… you will need to get the magnitudes of both values… in this script you set the max local scale to five times the size of the object!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Size_Changer : MonoBehaviour {
public Vector3 maxLocalScale;
float maxlocalScaleMagnitude;
void Start(){
maxLocalScale = new Vector3 (5, 5, 1);
maxlocalScaleMagnitude = maxLocalScale.magnitude;
}
void FixedUpdate () {
float actualLocalScaleMagnitude = transform.localScale.magnitude;
if ((Input.GetKey ("space")) && (actualLocalScaleMagnitude < maxlocalScaleMagnitude))
{
transform.localScale += new Vector3(0.1F, 0.1F, 0);
}
}
}