Last active
July 4, 2018 04:22
-
-
Save TeraokaAkihiro/28a97bd866aa09f45b4bb8ab6fcf8478 to your computer and use it in GitHub Desktop.
【Unity】カメラから見えなくなったときの判定方法 ref: https://qiita.com/teraokaakihiro/items/5e8f74ac3685d4937a5b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class LookChange : MonoBehaviour { //MonoBehaviourは呼ばれていないといけない | |
private bool flag = false; | |
void OnBecameInvisible() // カメラから見えなくなった時 | |
{ | |
if(flag==true) // 偶数回に見えなくなったときの処理 | |
{ | |
} | |
else // 最初、奇数回に見えなくなったときの処理 | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class LookChange : MonoBehaviour { | |
private bool fMaterial = false; | |
[SerializeField] | |
private Material mat01; | |
[SerializeField] | |
private Material mat02; | |
void OnBecameInvisible() | |
{ | |
if(fMaterial==true) | |
{ | |
this.GetComponent<Renderer>().material=mat01; | |
fMaterial=false; | |
} | |
else | |
{ | |
this.GetComponent<Renderer>().material=mat02; | |
fMaterial=true; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class LookChange : MonoBehaviour { | |
private bool fMaterial = false; | |
[SerializeField] | |
private Material mat01; | |
[SerializeField] | |
private Material mat02; | |
void OnBecameInvisible() | |
{ | |
if(fMaterial==true) | |
{ | |
this.GetComponent<Renderer>().material=mat01; | |
} | |
else | |
{ | |
this.GetComponent<Renderer>().material=mat02; | |
} | |
fMaterial = !fMaterial; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment