system
June 10, 2011, 8:44am
1
Hello, I have animation on my container Open close. Script attached to container itself.
I am operating it buy Input.GetButtonDown(“Fire1”); and private var Activated : boolean;
if (Input.GetButtonDown(“Fire1”) && CanPressButton == 1){
if(Physics.Raycast(ray.origin, ray.direction,hit, distanceToObj)){
if(hit.collider.gameObject.tag==obj && _Activated == false){//Variable here
currentObj = hit.collider.gameObject;
ObjectControl(Anim1Sound,true,anim1,currentObj);
}
else if(hit.collider.gameObject.tag==obj && _Activated == true)//Variable here
{
currentObj = hit.collider.gameObject;
ObjectControl(Anim2Sound,false,anim2,currentObj);
}
}
So when only one object on scene all works fine. Animation is works great. but when i duplicate that object and toching they . One Variable works for both. First object = true. then when i click other playing second animation (that need variable = true); How can variable works only for that object that i clicked?
save
June 10, 2011, 9:02am
2
You declare private variables to isolate events for duplicated objects with the same script.
private var canPressButton : boolean = false;
system
June 10, 2011, 9:46am
3
Thank u dude. That is all my code. What should i do?
class AnimateObject extends MonoBehaviour
{
public var playerCam : Camera;
public var obj : String;
public var HighLightColor : Color;
public var anim1 : String;
public var anim2 : String;
public var distanceToObj : float = 2.0;
private var currentObj : GameObject;
private var rHit;
var Anim1Sound : AudioClip;
var Anim2Sound : AudioClip;
private var CanPressButton : int = 1;
private var isOpen : boolean;
private var isClose : boolean;
private var isIdle : boolean = true;
private var _Activated : boolean = false;
function AnimateThatObj(obj,anim1 : String,anim2 : String)
{
var hit : RaycastHit;
var ray : Ray = playerCam.ScreenPointToRay(new Vector3(Screen.width * 0.5, Screen.height * 0.5, 0));
if (Input.GetButtonDown("Fire1") && CanPressButton == 1){
if(Physics.Raycast(ray.origin, ray.direction,hit, distanceToObj)){
if(hit.collider.gameObject.tag==obj && _Activated == false){
currentObj = hit.collider.gameObject;
ObjectControl(Anim1Sound,true,anim1,currentObj);
}
else if(hit.collider.gameObject.tag==obj && _Activated == true)
{
currentObj = hit.collider.gameObject;
ObjectControl(Anim2Sound,false,anim2,currentObj);
}
}
}//Input.GetButtonDown
Debug.Log(currentObj);
}
function ObjectControl(aClip : AudioClip, ActivatedCheck : boolean, animName : String, thisObj : GameObject)
{
audio.PlayOneShot(aClip);
_Activated = ActivatedCheck;
thisObj.animation[animName].wrapMode = WrapMode.Once;
thisObj.animation.Play(animName);
}
function AnimateCheking(){
if (currentObj != 0) {
if(currentObj.animation.isPlaying==true){
CanPressButton = 0;
}
else //Если нет
{
CanPressButton = 1;
}
}
}
function Awake()
{
}
function Update () {
AnimateThatObj(obj,anim1,anim2);
AnimateCheking();
}
}