Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Drop : MonoBehaviour {
- float grabPower = 10.0f;//скорость притяжения
- float throwPower = 10f;//скорость толчка
- RaycastHit hit;//луч
- float RayDistance = 3.0f;//дистанция
- private bool Grab = false;//ф-ция притяжения
- private bool Throw = false;//ф-ция толчка
- Transform offset;
- public GUITexture drop;
- void Update (){
- int count = Input.touchCount;
- for(int i = 0 ; i < count ; i++){
- Touch touch = Input.GetTouch(i);
- {//если нажата клавиша Е
- Physics.Raycast(transform.position, transform.forward, out hit, RayDistance);//физический луч
- if(hit.rigidbody){//если луч соприкасается с rigidbody
- Grab = true;
- }
- }
- if (drop.HitTest(touch.position)){//если нажата лев кн мыши
- if(Grab){
- Grab = false;
- Throw = true;
- }
- }
- if(Grab){//ф-ция притяжения
- if(hit.rigidbody){
- hit.rigidbody.velocity = (offset.position - (hit.transform.position + hit.rigidbody.centerOfMass))*grabPower;
- }
- }
- if(Throw){//ф-ция толчка
- if(hit.rigidbody){
- hit.rigidbody.velocity = transform.forward * throwPower;
- Throw = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement