- Home /
Scale On One Side Only
I know there have been many other questions on this topic but none of them have an answer that works for me. I have tried scaling an empty parent of the object snapped to the side, which works in the inspector but not script. I have tried moving the position after scaling, which however much I try doesn't work. By the way, I'm not using the line renderer for my laser, as that is not three-dimentional when viewed from behind. Here's the code of my laser that I'm trying to move.
public class laserScript : MonoBehaviour
{
public float damage = 10f;
public float range = 1000f;
public float distanceAway;
public GameObject laser;
private void Update()
{
if (Input.GetButton("BButton"))
{
distanceAway = range;
laser.SetActive(true);
Fire();
}
else if (!Input.GetButton("BButton"))
{
laser.SetActive(false);
}
}
public void Fire()
{
RaycastHit hit;
if (Physics.Raycast(transform.position,transform.forward, out hit, range))
{
distanceAway = hit.distance;
}
laser.transform.localScale = new Vector3(0.1f,distanceAway - 1,0.1f);
}
}
At the moment, this script I have been trying the scale the parent that is on one side of the laser. the laser gameobject seen in the script is referencing the parent.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
What is Matrix4x4? 2 Answers
How do i code a Mesh collider ? 1 Answer
Using animation curves for fall and roll-over in and endless runner 3d 0 Answers