- Home /
Lights and Scripting and Positions
Why would this happen.. I place a light and a sphere in the same position. But when I compile the game. The light is offset from the sphere. As I approach the Light and Sphere. The Light seems to move around the sphere and move off to the other side. If they a supposed to be in the same position, why then dose the light move all over the place?? I placed a flare on the light to watch what it is doing...
using System; using System.Collections.Generic; using System.Text; using UnityEngine;
[RequireComponent(typeof(Light))] class SoloSystem :MonoBehaviour { public string SoloSystemName = "Unnamed"; public int SoloSystemID = 0; public SunType Suntype = SunType.Type_O; public List<Planet> Plants = new List<Planet>();
void Start()
{
GameObject Sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Sphere.renderer.material.color = new Color(1.0f, 0.2f, 0.2f);
Sphere.transform.position = transform.position;
Sphere.transform.localScale = new Vector3(100.0f, 100.0f, 100.0f);
Sphere.renderer.castShadows = false;
Sphere.renderer.receiveShadows = false;
Sphere.light.enabled = true; // If I enable it turns off the other light...?? why
Sphere.light.range = (float)Suntype;
Sphere.light.intensity = (float)Suntype;
Label.target = Sphere.transform;
light.intensity = (float)Suntype; //Enum basically = 30000:int
light.range = (float)Suntype;
light.transform.position = Sphere.transform.position; // Trying to work out
light.transform.localScale = Sphere.transform.localScale; //trying to work out.
}
void Update()
{
}
}
I am new to this. So it might be something basic. I've only been playing around with it for 2 days...
Not an error as such, but use transform.position ins$$anonymous$$d of light.transform.position - theres no point getting the light component just so you can get the transform component from it
Answer by AliAzin · Aug 01, 2010 at 10:29 AM
Try adding
Sphere.transform.position = transform.position;
light.transform.position = Sphere.transform.position; // Trying to work out
light.transform.localScale = Sphere.transform.localScale; //trying to work out.
to Update instead of Start method if your transforms are changing.
Your answer
Follow this Question
Related Questions
lighting click help 3 Answers
light on collision help (scripting) 2 Answers
Shader errors 0 Answers
Positioning a GameObject so I't wont be inside another object 1 Answer
Weapon Possition Move On Sprint 1 Answer