- Home /
Question by
Dippimunch · Jul 20, 2014 at 03:23 PM ·
transformvariablesimple
Declaring variables in Update().
Simple code, but how do I declare a variable to use in an update function? Just trying to transform an object equally along X and Z axis.
using UnityEngine;
using System.Collections;
public class popcirc : MonoBehaviour {
// Use this for initialization
void Start () {
float size = Random.Range(-1.0F, 1.0F);
}
// Update is called once per frame
void Update () {
transform.localScale += new Vector3(size, 0, size);
}
}
Comment
Answer by gjf · Jul 20, 2014 at 03:27 PM
like this:
using UnityEngine;
using System.Collections;
public class popcirc : MonoBehaviour
{
private float size;
void Start()
{
size = Random.Range(-1.0F, 1.0F);
}
void Update()
{
transform.localScale += new Vector3(size, 0, size);
}
}
Answer by revapps · Jul 20, 2014 at 03:28 PM
using UnityEngine; using System.Collections;
public class popcirc : MonoBehaviour {
private float size;
// Use this for initialization
void Start () {
size = Random.Range(-1.0F, 1.0F);
}
// Update is called once per frame
void Update () {
transform.localScale += new Vector3(size, 0, size);
}
}
Your answer