- Home /
Question by
Mihaaa_123_123 · Oct 30, 2015 at 09:17 PM ·
unity 5sprite2d gameontriggerenterscaling
Scale Sprites Smoothly - problem
Hi! Im writing a script (C#) for scaling an object. I want to scale an object smooth with Vector3.Lerp, but it doesnt work!
plssss help!!!!!!!
the code for scaling:
Vector3 newsc= new Vector3(0.1f,0.1f,0);
transform.localScale = Vector3.Lerp(transform.localScale, newsc, Time.deltaTime);
//transform.localScale += newsc; <--- just scales object
the whole code: using UnityEngine; using System.Collections;
public class Eating : MonoBehaviour {
public int food;
public int size;
public int sizeSt;
public int fieldOf;
public Camera cam;
public PlayerMovement playerMovement;
public GameObject particle;
void Start () {
playerMovement.GetComponent<PlayerMovement>();
cam.GetComponent<Camera>();
food = 0;
sizeSt = 2;
}
void Update () {
if(fieldOf == 5)
{
cam.fieldOfView += 1;
fieldOf = 0;
}
if(size == sizeSt) <---- when size is 2
{
Grow ();
size = 0;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "food")
{
food += 1;
size += 1; <--- for size
fieldOf += 1;
Debug.Log ("hit");
Instantiate(particle, other.transform.position, other.transform.rotation);
Destroy(other.gameObject);
}
}
void Grow()
{
Vector3 povecava = new Vector3(0.1f,0.1f,0);
transform.localScale = Vector3.Lerp(transform.localScale, povecava, Time.deltaTime);
//transform.localScale += povecava;
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotating a 2D sprite(Ring) in a fixed position 0 Answers
Best Image Formats, Sizes, and Resolutions for Unity Sprites? 2 Answers
Sprite is stretched on Y scale bug (2D game) 1 Answer
How to change objects scale based on distance between 2 points 4 Answers
am trying to scaling my ground size in z direction until my player is moving, 2 Answers