Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class RuchYacht : MonoBehaviour {
  7.  
  8.     //zmienne wyswietlane
  9.     public float maxSpeed;
  10.     public float speed = 0;
  11.     public float UstawieniePletwy;
  12.     public float predObrot;
  13.  
  14.     //Nomoto
  15.     float wychylenie_pletwy;
  16.     float pletwa_sigmaR = 0;
  17.     float T = 50.66F;
  18.     float K = 0.007F;
  19.     float sigmaC = -0.0159F;
  20.     float rot = 0;
  21.     float cog;
  22.  
  23.     //zmienne pozycji poczatkowej
  24.     float z;
  25.     float x;
  26.  
  27.     public Slider SliderPredkosc;
  28.     public Slider SliderPletwy;
  29.     public Button btnZerujPred;
  30.  
  31.     // Use this for initialization
  32.     void Start()
  33.     {
  34.         x = transform.position.x;
  35.         z = transform.position.z;
  36.         cog = transform.eulerAngles.y;
  37.     }
  38.    
  39.     // Update is called once per frame
  40.     void FixedUpdate ()
  41.     {
  42.         maxSpeed = SliderPredkosc.value;
  43.         UstawieniePletwy = SliderPletwy.value;
  44.         // PREDKOSC
  45.         btnZerujPred.onClick.AddListener(TaskOnClick);
  46.  
  47.         pletwa_sigmaR = Mathf.MoveTowards(pletwa_sigmaR, SliderPletwy.value, 0.5F * Time.deltaTime * 5);
  48.         speed = Mathf.MoveTowards(speed, SliderPredkosc.value, 1.0F * Time.deltaTime * 5);
  49.  
  50.         rot += K * (sigmaC + pletwa_sigmaR) - rot * Time.deltaTime / T;
  51.         cog += rot * Time.deltaTime;
  52.  
  53.         x += speed * Time.deltaTime * cos(cog);
  54.         z += speed * Time.deltaTime * sin(cog);
  55.         predObrot = cog;
  56.        
  57.         transform.position = new Vector3(x, transform.position.y, z);
  58.         transform.rotation = Quaternion.Euler(0, cog, 0);
  59.     }
  60.  
  61.     private float sin (float alfa) { return Mathf.Sin(alfa * Mathf.PI / 180); }
  62.     private float cos (float alfa) { return Mathf.Cos(alfa * Mathf.PI / 180); }
  63.  
  64.     void TaskOnClick() //polecenie zerowania predkosci
  65.     {
  66.         SliderPredkosc.value = 0;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement