Scale Based On Proximity (Script Problems)
Hi, I'm trying to make a hallway that extends as you walk down it, and then retracts as you reach the end. I have a null representing a proximity tracker, and I've cobbled together the following script from other sources. It's not quite right, but I've hit my limit of C skills:
using UnityEngine;
using System.Collections;
public class ProxLength : MonoBehaviour {
public GameObject Player;
public GameObject Hallway;
public GameObject Tracker;
void Update()
{
var a = Player.position;
var b = Tracker.position;
var distance = Vector3.Distance(a, b);
var percent = Mathf.Clamp01(distance / range);
scaleChange = new Vector3(2f, 0f, 0);
Hallway.localScale = Vector3.Lerp(scaleChange * percent);
}
}
Figured out an alternate method to obtain the distance parameter, using floats:
using UnityEngine; using System.Collections;
public class DistCalc : $$anonymous$$onoBehaviour { public Transform other;
void Update()
{
if (other)
{
float dist = Vector3.Distance(other.position, transform.position);
Debug.Log("Distance: " + dist);
}
}
} <
I still don't know how to apply the result to the Vector3 x transform
Your answer
Follow this Question
Related Questions
Relative Position Not Constant? 0 Answers
Lambert W Function for C# 0 Answers
Reading a flowmap with script vs shadergraph 0 Answers
A graph to render sine wave with custom resolution 0 Answers
How do I stop this annoying transform from 'snapping'? 1 Answer