- Home /
Question by
kpdavid02 · May 09, 2017 at 05:49 AM ·
c#gameobjectif-statementsifif statement
Make script affect only one GameObject instead of making all object with this script be affected.
Help! So I have 3 objects in the scene with the "Object" Script. What I wanted is if a GameObject's Outline color == 1, make this GameObject's name "ThisOne". What happens is all the GameObject with the "Object" script also becomes "ThisOne".
Here is the code:
using System.Linq; using UnityEngine; using System.Collections.Generic;
namespace cakeslice{
public class Object : MonoBehaviour {
public string description;
private string originalName;
void Start () {
originalName = gameObject.name;
}
// Update is called once per frame
void Update () {
if (gameObject.GetComponent<Outline> ().color == 0) {
gameObject.transform.name = "ThisOne";
}
if (Input.GetKeyDown (KeyCode.Escape)) {
gameObject.name = originalName;
}
}
}
}
Comment