virtual public void Blow(Vector2 vel, BlowType blowType = BlowType.Normal) { if (blowType == BlowType.Normal) { state = PetalState.Fly; } else if (blowType == BlowType.FlyAway) { state = PetalState.FlyAway; } }
virtual public void OnLand(Vector3 point, Vector3 normal, GameObject obj) { Debug.Log("OnLand " + name + " " + obj.name); if (state == PetalState.Fly || state == PetalState.Init) { // set the petal stable if (GetComponent <Rigidbody>() != null) { GetComponent <Rigidbody>().isKinematic = true; } //Change the State of the petal if (state == PetalState.Init) { EventManager.Instance.PostEvent(EventDefine.GrowFirstFlower); } state = PetalState.Land; //check the land Land land = obj.GetComponent <Land>(); //Grow a new flower on the collision point Vector3 contactPoint = new Vector3(point.x, point.y, 0); Vector3 _normal = new Vector3(normal.x, normal.y, 0); Vector3 growPoint = contactPoint - _normal.normalized * 0.1f; //cast a ray to find if actual hit point int layerMask = 1 << LayerMask.NameToLayer("Land"); RaycastHit hitInfo; if (Physics.Raycast(point, Vector3.down, out hitInfo, 2f, layerMask)) { growPoint = Global.V2ToV3(hitInfo.point) + Vector3.down * hitInfo.distance * 2; } if (checkCanGrowFlower(growPoint, _normal, land)) { GrowFlowerOn(growPoint, _normal, obj.transform); } else { destoryMessage.AddMessage("onLand", 1); } transform.DOScale(0, 1f).OnComplete(SelfDestory); transform.DOMove(-0.1f * _normal, 1f).SetRelative(true).OnComplete(SelfDestory); } else if (state == PetalState.FlyAway) { transform.DOScale(0, 1f).OnComplete(SelfDestory); } }
public int GetPetalNumByType(PetalState compare) { int count = 0; foreach (Petal petal in petals) { if (petal.state == compare) { count++; } } return(count); }
public int GetPetalNumByType( PetalState compare ) { int count = 0; foreach(Petal petal in petals) { if ( petal.state == compare ) count ++ ; } return count; }
virtual public void Blow(Vector2 vel, BlowType blowType = BlowType.Normal) { if (blowType == BlowType.Normal ) state = PetalState.Fly; else if (blowType == BlowType.FlyAway) state = PetalState.FlyAway; }
virtual public void OnLand(Vector3 point , Vector3 normal , GameObject obj) { Debug.Log("OnLand " + name + " " + obj.name ); if ( state == PetalState.Fly || state == PetalState.Init ) { // set the petal stable if ( GetComponent<Rigidbody>() != null ) { GetComponent<Rigidbody>().isKinematic = true; } //Change the State of the petal if ( state == PetalState.Init ) EventManager.Instance.PostEvent( EventDefine.GrowFirstFlower ); state = PetalState.Land; //check the land Land land = obj.GetComponent<Land>(); //Grow a new flower on the collision point Vector3 contactPoint = new Vector3( point.x , point.y , 0 ); Vector3 _normal = new Vector3( normal.x , normal.y , 0 ); Vector3 growPoint = contactPoint - _normal.normalized * 0.1f; //cast a ray to find if actual hit point int layerMask = 1 << LayerMask.NameToLayer("Land"); RaycastHit hitInfo ; if ( Physics.Raycast( point , Vector3.down , out hitInfo, 2f , layerMask ) ) { growPoint = Global.V2ToV3( hitInfo.point ) + Vector3.down * hitInfo.distance * 2; } if (checkCanGrowFlower(growPoint , _normal , land)) { GrowFlowerOn(growPoint, _normal , obj.transform ); } else { destoryMessage.AddMessage("onLand" , 1); } transform.DOScale( 0 , 1f ).OnComplete(SelfDestory); transform.DOMove( - 0.1f * _normal , 1f ).SetRelative(true).OnComplete(SelfDestory); }else if ( state == PetalState.FlyAway) { transform.DOScale( 0 , 1f ).OnComplete(SelfDestory); } }