- Home /
whats wrong with this script. it wont work
using UnityEngine;
using System.Collections;
public class OcclusionCulling : MonoBehaviour {
private Renderer objThatCanBeCulled;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "guy") {
for (i = 0 ; i < objThatCanBeCulled.size; i++) {
{
objThatCanBeCulled[i].enabled = false;
}
}
}
}
}
Answer by HarshadK · Oct 01, 2014 at 06:32 AM
Actually you need to specify the exact errors otherwise it is not possible to provide precise solutions.
But here are a few things:
Your objThatCanBeCulled needs to be an array since you are accessing it as an array. your line where you declare it should be:
private Renderer[] objThatCanBeCulled;
And you instantiate array usually in Start or somewhere like:
void Start()
{
// This is an array of size 10
objThatCanBeCulled = new Renderer[10];
}
Also you access the size of an array using Length. Also 'i' should have a type. Correct statement will be:
for (int i = 0 ; i < objThatCanBeCulled.Length; i++)
I also assume that there are elements put inside your array.
And actually, it looks like you don't want that at all. Ins$$anonymous$$d, try getting the renderer component of the 'other' game object, and set enabled to false on that
Your answer
Follow this Question
Related Questions
[SOLVED] Problem with "foreach". 1 Answer
ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System. 0 Answers
Cutscene script help ? 0 Answers
Multiple Cars not working 1 Answer
Problems with instantiation... 1 Answer