0
\$\begingroup\$

This is the script I am working with:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Raise : MonoBehaviour
{
public GameObject Ladder;

float mfX;
float mfY;
float mfZ;
// Use this for initialization
void Start()
{
    mfX = Ladder.transform.position.x - Ladder.transform.localScale.x / 2.0f;
    mfY = Ladder.transform.position.y - Ladder.transform.localScale.y / 2.0f;
    mfZ = Ladder.transform.position.z - Ladder.transform.localScale.z / 2.0f;
}

// Update is called once per frame
void Update()
{
        Vector3 v3Scale = Ladder.transform.localScale;
        Ladder.transform.localScale = new Vector3(v3Scale.x + 0.1f, v3Scale.y + 0.1f, v3Scale.z + 0.1f);
        Ladder.transform.position = new Vector3(/*mfX + Ladder.transform.localScale.x / 2.0f*/0, mfY + Ladder.transform.localScale.y / 2.0f, mfZ + Ladder.transform.localScale.z / 2.0f);
}
}

The way it is now it's making the whole cube bigger and bigger.

But I want to make the cube grow only UP on Y. To keep the cube capacity/ extent But to make the scale change only up.

If I'm doing:

Vector3 v3Scale = Ladder.transform.localScale;
Ladder.transform.localScale = new Vector3(0, v3Scale.y + 0.1f, 0);
Ladder.transform.position = new Vector3(0, mfY + Ladder.transform.localScale.y / 2.0f, 0);

I will see it go up in scene if I select the cube in the hierarchy but if not I will not see the cube at all.

Can't figure out how to make is grow up only up side.

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

Here is the problem:

Ladder.transform.localScale = new Vector3(0, v3Scale.y + 0.1f, 0);

You have set scale Vector3 to (0, value, 0). It should be (1, value, 1). I suspect the reason you can't see anything is because you've told it that object shouldn't have an X or Z axis! Scale values should default to one, not zero.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .