Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: amirivala on October 21, 2014, 09:55:34 PM

Title: 3d Object Dont Rotate With NGUI Camera
Post by: amirivala on October 21, 2014, 09:55:34 PM
Hi i have a UI Root(3d) and i also have a 3d object that i want to rotate it with Lerp, my object rotate perfectly with unity Camera but when i add NGUI 3d Camera, it stopped working and i know that my code is not working with NGUI, but is there a way to make it work?
(I KNOW NGUI HAS AN EXAMPLE THAT HAS ROTATE OBJECT BUT THAT DOSEN'T HAVE LERP)
Please help me I'm new to coding
thank you a lot
I Really appreciate it

Here is my code:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DragRotateSlowdown : MonoBehaviour {
  5.        
  6.         public float rotationSpeed = 10.0F;
  7.         public float lerpSpeed = 1.0F;
  8.        
  9.         private Vector3 theSpeed;
  10.         private Vector3 avgSpeed;
  11.         private bool isDragging = false;
  12.         private Vector3 targetSpeedX;
  13.        
  14.         void OnMouseDown() {
  15.                
  16.                 isDragging = true;
  17.         }
  18.        
  19.         void Update() {
  20.  
  21.                
  22.                 if (Input.touchCount > 0 && isDragging) {
  23.                         theSpeed = new Vector3(-Input.touches[0].deltaPosition.x, Input.touches[0].deltaPosition.y, 0.0F);
  24.                         avgSpeed = Vector3.Lerp(avgSpeed, theSpeed, Time.deltaTime * 5);
  25.                 } else {
  26.                         if (isDragging) {
  27.                                 theSpeed = avgSpeed;
  28.                                 isDragging = false;
  29.                         }
  30.                         float i = Time.deltaTime * lerpSpeed;
  31.                         theSpeed = Vector3.Lerp(theSpeed, Vector3.zero, i);
  32.                 }
  33.                
  34.                 transform.Rotate(Camera.main.transform.up * theSpeed.x * rotationSpeed, Space.World);
  35.                 transform.Rotate(Camera.main.transform.right * theSpeed.y * rotationSpeed, Space.World);
  36.         }
  37. }
Title: Re: 3d Object Dont Rotate With NGUI Camera
Post by: ArenMook on October 22, 2014, 05:37:29 AM
OnMouseDown is a Unity callback. NGUI's equivalent is OnPress(bool isPressed).