Exemplo n.º 1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 2
0
 public void DropItem()
 {
     found.transform.SetParent(null);
     RobotGrabber.SetCollidersInItem(found.transform, true);
     found = null;
 }
Exemplo n.º 3
0
        override public void Update()
        {
            base.Update();
            if (DB.atPoint)
            {
                if (hasCrystal)
                {
                    //put crystal
                    DropItem();
                }
                else
                {
                    //take crystal
                    foreach (DragonInterest sensed in DB.DS.SensedCrystals)
                    {
                        if (sensed == DB.DSA.most_crystal)
                        {
                            found = sensed;
                            break;
                        }
                    }
                    if (found)
                    {
                        RobotGrabber.SetCollidersInItem(found.transform, false);
                        found.transform.SetParent(HoldingPoint);
                        found.transform.localPosition = Vector3.zero;
                        DB.SetNewTarget(DragonManager.Instance.nests [Random.Range(0, DragonManager.Instance.nests.Length)].position);
                    }
                    else
                    {
                        print("smth wrong with grabbing crystal");
                    }
                }
            }
            else
            {
                if (DB.path_built)
                {
                    float sqrDist2target = (DB.targetPoint - DB.transform.position).sqrMagnitude;
                    if (sqrDist2target < sqrDist2Land)
                    {
                        DB.atPoint = true;

                        DB.DM.flying = false;
                    }
                    else
                    {
                        float dist2body = (DB.DM.transform.position - DB.transform.position).sqrMagnitude;
                        if (dist2body < sqrDist2Keep)
                        {
                            DB.progress += (dist2Keep) / DB.curve.length * Time.deltaTime;
                            Vector3 dir = DB.curve.GetPointAt(DB.progress + Time.deltaTime) - DB.curve.GetPointAt(DB.progress);
                            dir.y = 0;
                            if (dir != Vector3.zero)
                            {
                                DB.transform.rotation = Quaternion.LookRotation(dir);
                            }
                            DB.transform.position = DB.curve.GetPointAt(DB.progress);
                            DB.DM.flying          = true;
                        }
                    }
                }
            }
        }