- Home /
Transform.localPosition Scripting Problem.
Hello. I have created a script that, when a certain object is touched, moves the parents selected and moves them along the Z axis. The script is
using UnityEngine;
using System.Collections;
public class Expands : MonoBehaviour {
public Transform parent;
public float expandAmount = 1.5f;
public float localPosition = 1f;
void OnMouseDown()
{
parent.localScale *=expandAmount;
parent.localPosition *= localPosition;
for(int i =0;i<parent.childCount;i++)
{
parent.GetChild(i).localScale =new Vector3(1/parent.localScale.x,1/parent.localScale.y, 1/parent.localScale.z);
parent.GetChild(i).localPosition = new Vector3(0, 0, -1f);
}
}
}
The script does move the objects down the Z axis as I wanted, but it also changes the Y and X positions to 0, which is not what I want. How can the script be modified so that the Y and X positions do not change. This game is 2D and for the Android. All help is appreciated.
Answer by Funlamb · Mar 15, 2015 at 05:48 AM
Maybe try:
parent.GetChild(i).localPosition += new Vector3(0, 0, -1f);//Added a '+'
If it is that simple I think it might be time to go to bed. I've been program$$anonymous$$g for a while today as well. I think it's tile for me to go to bed.
I am actually surprised at how simple that seems. Thanks!
Also I just want to clarify I am very new to Scripting ( Hopes that clears things up )
Your answer
Follow this Question
Related Questions
Expand object on touch? 1 Answer
Transform.LocalScale Script Problem. Please help. 2 Answers
Expand Object On Touch? Someone please help me 1 Answer
Collision On Specific Object= Destroy not working. 2 Answers
Scaling Script? 1 Answer