using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Walls : MonoBehaviour
{
public GameObject gameObjectToRaise;
public int raiseAmount;
public float speed;
private GameObject objtoraise;
private void Start()
{
objtoraise = Instantiate(gameObjectToRaise);
objtoraise.name = "Walls";
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
objtoraise.transform.localScale = Vector3.Lerp(objtoraise.transform.localScale,
new Vector3(objtoraise.transform.localScale.x + raiseAmount,
objtoraise.transform.localScale.y + raiseAmount,
objtoraise.transform.localScale.z), speed * Time.deltaTime);
}
}
}
If I set the speed to 1 in the editor it will scale to some shape but if I set the speed to 0.3 or to 5 it will show a different shape. The speed for some reason have a factor on the scaling.
Instead of that atrociously gnarly line 24 which sprawls across four lines of text, I suggest you instead calculate the individual inputs into temporary variables first so that you can reason about each step of the process, printing the values out with Debug.Log()
For instance, the first thing that springs to mind is that your localScale is being manipulated, AND you are subsequently feeding it back into the first term of the Vector3.Lerp(). That seems … wrong. Wouldn’t you want to freeze the initial location if you were doing a Lerp? Or are you going for a damping effect?