-2
\$\begingroup\$

I am very new to coding and very bad at it.

In my environnement there is a table, and i would like, after pressing a keyboard button, to make a cube appear. Then, by pressing another button, i would like to change its size everytime i press the second button.

I have no clue where to begin with.

Thanks in advance,

Kel

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What did you try that did not work? \$\endgroup\$ – Vaillancourt Mar 23 '15 at 13:33
  • \$\begingroup\$ Until now, we have a script created that make cubes appear, and everytime we press a button the cube mooves on the z axis of the table. I would like to make it change size instead. \$\endgroup\$ – kel Mar 23 '15 at 13:37
1
\$\begingroup\$

If you're creating a new gameObject using something along the lines of CreatePrimitive then you could following that with some logic to change it's scale programatically {Warning: untested code} :

public class SceneController : MonoBehaviour {

private GameObject cube;
private float cubeScale = 1.0f;

    void Awake() {

    }

    void Start() {

    }

    void Update() {
        // create cube
        if(Input.GetKeyDown (KeyCode.Space) {
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            // reposition cube randomly/rotate it etc
        }
        // size cube up
        var s = cube.transform.localScale;
        if(Input.GetKeyDown (KeyCode.Up) {
            cubeScale *= 1.1f;
            cube.transform.localScale += new Vector3(s.x * cubeScale, s.y * cubeScale, s.z * cubeScale);
        // size cube down
        } else if(Input.GetKeyDown (KeyCode.Down) { 
            cubeScale *= 0.9f;
            cube.transform.localScale += new Vector3(s.x * cubeScale, s.y * cubeScale, s.z * cubeScale);
        }
    }
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Cool, if you're satisfied then mark the question as answered. \$\endgroup\$ – DanoThom Mar 23 '15 at 16:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.