예제 #1
0
    // Функция* Показ панель предмета
    void DetectItem()
    {
        RaycastHit pickHit;
        Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));

        if (Physics.Raycast(ray, out pickHit, 3, LayerMask.GetMask("Door")))
        {
            CrossHair.color = Color.blue;
            if (Input.GetMouseButtonDown(0))
            {
                if (pickHit.transform.tag == "brakebale")
                {
                    if (GetComponent <SubjectUse> ().MyModel.GetComponent <Item> ().item.id == 201)
                    {
                        if (pickHit.transform.GetComponent <DoorScript> ())
                        {
                            DoorScript _script = pickHit.transform.GetComponent <DoorScript> ();
                            _script.hp -= 20;
                            if (_script.hp <= 0)
                            {
                                _script.Locked = false;
                                _script.OpenDoor();
                            }
                            Player.GetComponent <Animator> ().SetBool("punch", true);
                            HitHair.gameObject.SetActive(true);
                            ChangeTimer(true, 3, 0.2f);
                            return;
                        }
                    }
                }
            }
        }
        else if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Door")))
        {
            CrossHair.color = Color.green;
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (pickHit.transform.GetComponent <MechanicDoorScript> ())
                {
                    MechanicDoorScript _script = pickHit.transform.GetComponent <MechanicDoorScript> ();
                    if (_script.Locked)
                    {
                        _script.OpenLockedDoor();
                    }
                    else
                    {
                        _script.OpenDoor();
                    }
                }
                else if (pickHit.transform.GetComponent <DoorScript> ())
                {
                    DoorScript _script = pickHit.transform.GetComponent <DoorScript> ();
                    if (!_script.Locked)
                    {
                        _script.OpenDoor();
                    }
                }
            }
            if (GetComponent <SubjectUse> ().MyModel)
            {
                Subject MyModel = GetComponent <SubjectUse> ().MyModel.GetComponent <Item> ().item;
                if (MyModel.id == 2 && Input.GetKeyDown(KeyCode.E))
                {
                    if (Player.GetComponent <FirstPersonController> ().m_PreviouslyGrounded)
                    {
                        if (pickHit.transform.GetComponent <DoorScript> ())
                        {
                            if (pickHit.transform.GetComponent <DoorScript> ())
                            {
                                DoorScript script = pickHit.transform.GetComponent <DoorScript> ();
                                if (script.Locked)
                                {
                                    script.OpenLockedDoor(MyModel.value);
                                }
                                else
                                {
                                    script.OpenDoor();
                                }
                            }
                        }
                    }
                }
            }
        }
        else if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Static")))
        {
        }
        else if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Interactible")))
        {
            CrossHair.color = Color.green;
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (GetComponent <SubjectUse> ().MyModel)
                {
                    if (GetComponent <SubjectUse> ().MyModel.GetComponent <Item> ().item.id == 103)
                    {
                        ChangeTimer(true, 2, 1.5f);
                        pickHit.transform.gameObject.layer = LayerMask.GetMask("Default");
                        pickHit.transform.parent.GetChild(1).gameObject.layer = LayerMask.GetMask("Default");
                    }
                }
                if (pickHit.transform.tag == "box")
                {
                    pickHit.transform.tag = "Untagged";
                    NotificationIns(pickHit.transform.GetChild(0).GetComponent <Item>(), false);
                    AddItem(pickHit.transform.GetChild(0).GetComponent <Item>().gameObject);
                }
                if (pickHit.transform.tag == "button")
                {
                    GameInstaller.item.name = "Что-то прозвучало около поезда, нужно проверить";
                    NotificationIns(GameInstaller, true);
                    GameInstaller.GetComponent <GameInstaller> ().OpentwoDoor();
                }
            }
        }
        else if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Pickable")))
        {
            if (pickHit.transform.GetComponent <Item>() != null)
            {
                CrossHair.color = Color.green;
                Item itemEq = pickHit.transform.GetComponent <Item>();
                if (!Input.GetKeyDown(KeyCode.E))
                {
                    Detected.text = itemEq.item.name;
                }
                else
                {
                    NotificationIns(itemEq, false);
                    AddItem(itemEq.gameObject);
                }
            }
        }
        else if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Item")))
        {
            Item itemEq = pickHit.transform.GetComponent <Item>();
            if (itemEq != null)
            {
                CrossHair.color = Color.green;
                if (!Input.GetKeyDown(KeyCode.E))
                {
                    Detected.text = itemEq.item.name;
                }
                else
                {
                    NotificationIns(itemEq, false);
                    AddItem(itemEq.gameObject);
                }
            }
            else
            {
                itemEq = pickHit.transform.parent.GetComponent <Item>();
                if (itemEq)
                {
                    CrossHair.color = Color.green;
                    if (!Input.GetKeyDown(KeyCode.E))
                    {
                        Detected.text = itemEq.item.name;
                    }
                    else
                    {
                        NotificationIns(itemEq, false);
                        AddItem(itemEq.gameObject);
                    }
                }
            }
            return;
        }
        else
        {
            CrossHair.color = Color.red;
            if (Detected.text != "")
            {
                Detected.text = "";
                return;
            }
        }
    }
예제 #2
0
 void FixedUpdate()
 {
     if (GrabingObject)
     {
         Grabing();
     }
     if (newPlace != null)
     {
         Animate(newPlace);
     }
     else
     {
         if (UsingModel)
         {
             if (MyModel)
             {
                 if (Input.GetMouseButtonDown(0))
                 {
                     if (!DontPickable)
                     {
                         if (UsingOriginPosition)
                         {
                             Animate(PickOffset);
                         }
                         else
                         {
                             UsingModel = false;
                             MyModel.GetComponent <Rigidbody> ().velocity = transform.forward * throwPower;
                             //MyModel.gameObject.tag = "Untagged";
                             SetComponent(null, true);
                             throwPower = 10;
                             grabPower  = 10;
                             MyModel    = null;
                             if (GrabingObject)
                             {
                                 GrabingObject = false;
                             }
                         }
                     }
                     else
                     {
                         if (MyModel.GetComponent <Item>().item.id == 102)
                         {
                             transform.GetComponent <PlayerInventory>().ChangeTimer(true, 1, 1.5f);
                         }
                     }
                 }
                 else if (Input.GetMouseButtonDown(1) && !GrabingObject)
                 {
                     if (UsingOriginPosition)
                     {
                         transform.GetComponent <PlayerInventory> ().AddItem(MyModel.gameObject);
                         transform.GetComponent <PlayerInventory> ().NotificationIns(MyModel.GetComponent <Item>(), false);
                         Destroy(MyModel);
                         MyModel    = null;
                         UsingModel = false;
                     }
                     else
                     {
                         Animate(OriginOffset);
                     }
                 }
                 else
                 {
                     if (!GrabingObject)
                     {
                         RaycastHit pickHit;
                         Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
                         if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Door")))
                         {
                             if (MyModel.GetComponent <Item>().item.active&& Input.GetKeyDown(KeyCode.E))
                             {
                                 if (transform.GetComponent <FirstPersonController>().m_PreviouslyGrounded)
                                 {
                                     if (pickHit.transform.GetComponent <DoorScript>())
                                     {
                                         if (pickHit.transform.GetComponent <DoorScript>())
                                         {
                                             DoorScript script = pickHit.transform.GetComponent <DoorScript>();
                                             if (script.Locked)
                                             {
                                                 script.OpenLockedDoor(MyModel.GetComponent <Item>().item.value);
                                             }
                                             else
                                             {
                                                 script.OpenDoor();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             RaycastHit pickHit;
             Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
             if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Pickable")))
             {
                 if (Input.GetMouseButtonDown(1))
                 {
                     newPlace            = null;
                     UsingModel          = true;
                     MyModel             = pickHit.transform;
                     DontPickable        = false;
                     UsingOriginPosition = false;
                     GrabingObject       = true;
                     if (MyModel.gameObject.tag == "Hanger")
                     {
                         throwPower = 0;
                         grabPower  = 3;
                     }
                     Grabing();
                 }
             }
             else if (Physics.Raycast(ray, out pickHit, EquipDistance, LayerMask.GetMask("Door")))
             {
                 if (Input.GetKeyDown(KeyCode.E))
                 {
                     if (pickHit.transform.GetComponent <MechanicDoorScript>())
                     {
                         MechanicDoorScript _script = pickHit.transform.GetComponent <MechanicDoorScript>();
                         if (_script.Locked)
                         {
                             _script.OpenLockedDoor();
                         }
                         else
                         {
                             _script.OpenDoor();
                         }
                     }
                 }
             }
         }
     }
 }