- Home /
Problem with multiple gameobjects using same script.
Hi everybody i am developing a game, the game is about escaping from the jail.
My problem is that i have an script called hide. where it will register if player comes inside the area, and i have another script called Catched that has a boolean to turn true. My problem is that when i use the hide script with one game object it works but using the hide script with multiple gameobjects it only registers with the last gameobject added to the game.
using UnityEngine;
using System.Collections;
using UnityEngine.Assertions.Must;
public class Hide : MonoBehaviour {
public Transform[] HideCast;
public Catched catcher;
// Use this for initialization
void Start () {
}
public void Update()
{
Debug.DrawLine(gameObject.transform.position, HideCast[0].position, Color.red);
Debug.DrawLine(gameObject.transform.position, HideCast[1].position, Color.red);
Debug.DrawLine(HideCast[1].position, HideCast[0].position, Color.red);
catcher.hider = Physics2D.Linecast(gameObject.transform.localPosition, HideCast[0].position, 1 << LayerMask.NameToLayer("Player"))
|| Physics2D.Linecast(gameObject.transform.localPosition, HideCast[1].position, 1 << LayerMask.NameToLayer("Player"))
|| Physics2D.Linecast(HideCast[1].position, HideCast[0].position, 1 << LayerMask.NameToLayer("Player"));
}
}
Sorry for bad english Hope you guys can help me. Best Regards Fatih Karaman
Your answer
Follow this Question
Related Questions
Destroying objects with the same name that are touching eachother. 1 Answer
OnTriggerEnter() not firing for mutliple objects 0 Answers
how to detect an gameobject on mouse click using raycast 1 Answer
Multiple GameObjects with the same script all react but I only want one at a time. 2 Answers
Create multiple prefabs from multiple objects in the selection of the Hierarchy (Unity 5.3.5) 1 Answer