Cannot apply indexing with [] to an expression of type `UnityEngine.Transform'
I have 2 errors 1.Assets/gametime.cs(29,57): error CS1061: Type UnityEngine.Transform' does not contain a definition for
Length' and no extension method Length' of type
UnityEngine.Transform' could be found (are you missing a using directive or an assembly reference?) 2.Assets/gametime.cs(30,25): error CS0021: Cannot apply indexing with [] to an expression of type `UnityEngine.Transform'
using UnityEngine;
using System.Collections;
public class gametime : MonoBehaviour {
public Transform DirectionalLight;
public float dayCycleInMinutes = 1;
private const float SECOND = 1;
private const float MINUTE = 60 * SECOND;
private const float HOUR = 60 * MINUTE;
private const float DAY = 24 * HOUR;
private const float DEGREES_PER_SECOND = 360 / DAY;
private float _degreeRotation;
private float _timeOfDay;
// Use this for initialization
void Start () {
_timeOfDay = 0;
_degreeRotation = DEGREES_PER_SECOND * DAY / (dayCycleInMinutes * MINUTE);
}
// Update is called once per frame
void Update () {
for(int cnt = 0; cnt < DirectionalLight.Length; cnt ++)
DirectionalLight [cnt].Rotate(new Vector3(_degreeRotation, 0, 0) * Time.deltaTime);
_timeOfDay += Time.deltaTime;
Debug.Log (_timeOfDay);
}
}
your variable is a Transform
so you can only access its member variables/methods. if you had an array of Transform
s then you'd be able to...
what are you trying to do?
Your answer
Follow this Question
Related Questions
var script : GameObject 2 Answers
cannot convert UnityEngine.GameObject to PlayerController 0 Answers
Cannot implicitly convert type 'UnityEngine.GameObjects[]' to 'float' 2 Answers
Can't find XR in UnityEngine(missing package import) -- UnityEngine.VR not updated 0 Answers
Need to replace UnityEngine.UI after it got removed somehow 0 Answers