Wallpaper Engine

Wallpaper Engine

Ikke nok vurderinger
Furry Girl Lite
   
Pris
Føj til foretrukne
Gjort til foretrukken
Fjern som foretrukken
Age Rating: Everyone
Genre: Animal
Resolution: Other resolution
Category: Wallpaper
Filstørrelse:
Offentliggjort:
37.511 MB
31. okt. 2016 kl. 20:01
1 ændringsbemærkning ( vis )

Abonner for at downloade
Furry Girl Lite

Beskrivelse
Simple character looking at the mouse cursor algorithm.

Here is the code in C#
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LookAtMouse : MonoBehaviour
{

// speed is the rate at which the object will rotate

public float speed = 10f;

Plane ground;

public bool GameFocus;
public float timeStamp;
public float coolDownPeriodInSeconds;
Quaternion randomTarget;

void Awake()
{
// it is kinda important to make this app run in background, for the random target work.
Application.runInBackground = true;
}

void Update()
{
RotateToMousePosition();
}

void RotateToMousePosition()
{
ground = new Plane(Vector3.back , transform.position);

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

//*distance only needs an initial value to work
float dist = 0f;

if (ground.Raycast(ray, out dist))
{
//create a vector position at latest raycast hit point
Vector3 mousePoint = new Vector3(ray.GetPoint(dist).x,
ray.GetPoint(dist).y, (ray.GetPoint(dist).z - 2));

//*useful for showing where ray comes from in testing ONLY
Debug.DrawLine(ray.origin, mousePoint);

//rotate object toward vector position
Quaternion targetRotation = Quaternion.LookRotation(mousePoint - transform.position);
//IF Game has focus, it will look to targetRotation, else, will randonly generate a location
if (GameFocus)
{
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
else
{
if (timeStamp <= Time.time)
{
randomTarget = Quaternion.LookRotation(new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), -4.9f));
timeStamp = Time.time + coolDownPeriodInSeconds;
}
transform.rotation = Quaternion.Slerp(transform.rotation, randomTarget, speed * Time.deltaTime);
}
}
}

// this is the function to check if the app has focus
void OnApplicationFocus(bool hasFocus)
{
GameFocus = hasFocus;
}
}
1 kommentarer
Luckyday 17. feb. 2017 kl. 2:40 
very good