本文整理汇总了C#中UnityEngine.Quaternion.SetLookRotation方法的典型用法代码示例。如果您正苦于以下问题:C# Quaternion.SetLookRotation方法的具体用法?C# Quaternion.SetLookRotation怎么用?C# Quaternion.SetLookRotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Quaternion
的用法示例。
在下文中一共展示了Quaternion.SetLookRotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Turning
void Turning()
{
if(movement.Equals(Vector3.zero))
return;
Quaternion rot = new Quaternion();
rot.SetLookRotation(movement);
transform.rotation = rot;
}
示例2: createObject
public void createObject()
{
GameObject g;
g = (GameObject)Instantiate(script.gameObject, script.pos, new Quaternion());
if(script.parent != null){
g.transform.parent = script.parent;
}
Vector3 pos = createRandomVector3();
float distance = Random.Range(0, script.range);
pos = pos * distance;
g.transform.position = g.transform.position + pos;
//Set the height
float y = script.terrain.SampleHeight(g.transform.position);
g.transform.position = new Vector3(g.transform.position.x, y, g.transform.position.z);
//Rotate the objct
if(script.rotateRandom){
Quaternion rotation = new Quaternion();
rotation.SetLookRotation(createRandomVector3());
g.transform.rotation = rotation;
}
}
示例3: SetDestination
protected void SetDestination()
{
// Construct a ray from the current mouse coordinates
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit))
{
if (particleClone != null)
{
GameObject.Destroy(particleClone);
particleClone = null;
}
Vector3 p = hit.point + (transform.position - hit.point).normalized*2;
// Create a particle if hit
Quaternion q = new Quaternion();
q.SetLookRotation(hit.normal, Vector3.forward);
particleClone = Instantiate(particle, p, q);
print (hit.transform.name);
if(hit.transform.tag == "Goal"){
agent.destination = transform.position - (transform.position - hit.point).normalized;
}else{
agent.destination = p;
}
}
}
示例4: CreateMenu
public void CreateMenu()
{
if (main != null)
{
GameScriptSil mainGameScript = main.GetComponent("GameScriptSil") as GameScriptSil;
if (mainGameScript.enabled)
{
mainGameScript.enabled = false;
}
}
buttonPlanes = new GameObject[menuRows * menuColumns];
buttonCubes = new GameObject[menuRows * menuColumns];
for (int i = 0; i < menuColumns; i++)
{
for (int o = 0; o < menuRows; o++)
{
buttonCubes[menuRows*i + o] = GameObject.CreatePrimitive(PrimitiveType.Cube);//create cube
buttonCubes[menuRows*i + o].transform.localScale = new Vector3(1, 1, 0.1f);//flatten it
buttonCubes[menuRows*i + o].transform.position = new Vector3((i * 1.2f) - (0.1125f*(float)Math.Pow(menuColumns, 2)),(o * 1.2f) - (0.05625f*(float)Math.Pow(menuRows, 2)),-1);//move them
buttonCubes[menuRows*i + o].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/back") as Texture2D;//load texture
buttonPlanes[menuRows*i + o] = GameObject.CreatePrimitive(PrimitiveType.Plane);//create plane
buttonPlanes[menuRows*i + o].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);//shrink them
Quaternion q = new Quaternion(0, 0, 0, 1);//create rotation quaternion
q.SetLookRotation(new Vector3(0,-1000,-1), new Vector3(0,1,0));//assign values to quaternion
buttonPlanes[menuRows*i + o].transform.rotation = q;//assign quaternion to object
buttonPlanes[menuRows*i + o].transform.position = new Vector3((i * 1.2f) - (0.1125f*(float)Math.Pow(menuColumns, 2)),(o * 1.2f) - (0.05625f*(float)Math.Pow(menuRows, 2)),-1.051f);//move them
buttonCubes[menuRows*i + o].transform.parent = buttonPlanes[menuRows*i + o].transform;//make plane parent of cube
buttonPlanes[menuRows*i + o].GetComponent<Renderer>().material.shader = Shader.Find("Particles/Alpha Blended");//set shader
buttonCubes[menuRows*i + o].GetComponent<Renderer>().material.shader = Shader.Find("Particles/Alpha Blended");//set shader
Destroy(buttonPlanes[menuRows*i + o].GetComponent<Collider>());
buttonPlanes[menuRows*i + o].AddComponent<BoxCollider>();
Rigidbody gameObjectsRigidBody = buttonPlanes[menuRows*i + o].AddComponent<Rigidbody>(); // Add the rigidbody.
gameObjectsRigidBody.mass = 5;//set weight
gameObjectsRigidBody.useGravity = false;//disable gravity
buttonPlanes[menuRows*i + o].tag = "PicMenuItem";
}
}
string[] resourcePacks = Directory.GetDirectories(Environment.CurrentDirectory + "\\Assets\\Resources\\Textures\\Pictures\\" + gameType + "\\");
for (int i = 0; i < resourcePacks.Length; i++)
{
string[] s = resourcePacks[i].Split('\\');
buttonPlanes [i].name = s[s.Length - 1];
buttonPlanes [i].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/Pictures/" + gameType + "/" + s[s.Length - 1] + "/00") as Texture2D;
}
for (int i = resourcePacks.Length; i < menuColumns*menuRows; i++)
{
buttonPlanes [i].name = "Empty";
buttonPlanes [i].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/back") as Texture2D;
}
}
示例5: AddAccelerationStreak
public void AddAccelerationStreak()
{
GameObject streak = GameObject.Instantiate(accelerationParticleSystemPrefab, new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z), Quaternion.identity) as GameObject;
streak.transform.SetParent(player.transform);
Quaternion q = new Quaternion();
q.SetLookRotation(Vector3.left, Vector3.up);
streak.transform.rotation = q;
accelerationStreakStack.Push(streak);
}
示例6: HitTestWithRoad
public bool HitTestWithRoad()
{
Vector3 position = transform.position + transform.TransformDirection(Vector3.up) * 0.2f;
Vector3 direction = transform.TransformDirection(Vector3.down);
Ray ray = new Ray(position, direction);
RaycastHit hit;
Debug.DrawLine(ray.origin, ray.origin + ray.direction * distance, Color.red);
bool inGround = false;
if (Physics.Raycast(ray, out hit, distance)) {
if (hit.collider.tag == "Road"){
inGround = true;
this.transform.position = hit.point;
Debug.DrawLine(hit.point, hit.point + hit.normal, Color.green);
Vector3 current = position - hit.point;
Vector3 target= hit.normal;
Debug.DrawLine(hit.point, hit.point + current.normalized, Color.white);
Quaternion targetQ = new Quaternion();
//TODO: Using "velocity.normalize" instead of "Vector3(0, 1.0, 1.0)"
Vector3 fPosition= transform.position + transform.TransformDirection(new Vector3(0, 1.0f, 1.0f));
Vector3 fDirection= transform.TransformDirection(Vector3.down);
Ray fRay= new Ray(fPosition, fDirection);
RaycastHit fHit;
float fDistance= 2;
Debug.DrawLine(fRay.origin, fRay.origin + fRay.direction * fDistance, Color.cyan);
if (Physics.Raycast(fRay, out fHit, fDistance)) {
if (fHit.collider.tag == "Road"){
Debug.DrawLine(fHit.point, fHit.point + fHit.normal * fDistance, Color.magenta);
targetQ.SetLookRotation(fHit.point - transform.position, target);
}
}
if (targetQ == null) {
targetQ.SetLookRotation(transform.TransformDirection(Vector3.forward), target);
}
this.gameObject.transform.rotation = Quaternion.Slerp(this.gameObject.transform.rotation, targetQ, smoothRatio);
}
}
return inGround;
}
示例7: OnCollisionEnter
void OnCollisionEnter(Collision other) {
if (other.gameObject.tag != "Player") {
Vector3 yolkPosition = other.collider.bounds.ClosestPoint (other.contacts[0].point);
yolkPosition.y = other.collider.ClosestPointOnBounds(other.contacts[0].point).y;
Quaternion yolkRotation = new Quaternion ();
yolkRotation.SetLookRotation (new Vector3(1, 0, 0), other.contacts[0].normal);
Instantiate (yolk, yolkPosition, yolkRotation);
Destroy (gameObject);
}
}
示例8: Update
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis ("Vertical");
GetComponent<Rigidbody>().velocity = new Vector3 (horizontal * speed, GetComponent<Rigidbody>().velocity.y, vertical * speed);
if (horizontal == 0 && vertical == 0) {
return;
}
Quaternion q = new Quaternion ();
q.SetLookRotation(new Vector3 (horizontal, 0, vertical));
GetComponent<Rigidbody>().rotation = q;
}
示例9: OnSceneGUI
public void OnSceneGUI()
{
Waypoint wp = (Waypoint)target;
//Handles.Label(wp.transform.position + Vector3.up * (wp.transform.localScale.y*2/3), "Test!");
if (debug && wp.next != null) {
//wp.transform.LookAt(wp.next.transform);
Quaternion q = new Quaternion (wp.transform.rotation.x, wp.transform.rotation.y, wp.transform.rotation.z, wp.transform.rotation.w);
q.SetLookRotation (wp.next.transform.position - wp.transform.position);
Handles.ArrowCap (0, wp.transform.position, q, HandleUtility.GetHandleSize (wp.transform.position));
Handles.DrawLine (wp.transform.position, wp.next.transform.position);
}
}
示例10: calculateTarget
//Given a target position, set the target rotation
void calculateTarget(Vector3 inputOffset)
{
targetPosition = targetLocation.position;
targetPosition += targetLocation.forward * inputOffset.z;
targetPosition += targetLocation.right * inputOffset.x;
targetPosition += targetLocation.up * inputOffset.y;
targetRotation = Quaternion.identity;
if((targetLocation.position - targetPosition) != Vector3.zero)
{
targetRotation.SetLookRotation( targetLocation.position - targetPosition, targetLocation.up);
}
}
示例11: FixedUpdate
void FixedUpdate()
{
target = FindClosest();
// look at target
Quaternion rotation = new Quaternion();
transform.LookAt(target.transform);
rotation.SetLookRotation(Vector3.forward, Vector3.up);
transform.localRotation = rotation;
// accelerate towards target
Vector2 targetDirection = new Vector2(target.transform.position.x - transform.position.x, target.transform.position.y - transform.position.y);
targetDirection.Normalize();
rigidbody2D.AddForce(targetDirection * force);
}
示例12: CreateMenu
public void CreateMenu()
{
resourcePackMenu.SetActive(false);
buttonPlanes = new GameObject[menuRows * menuColumns];
buttonCubes = new GameObject[menuRows * menuColumns];
for (int i = 0; i < menuColumns; i++)
{
for (int o = 0; o < menuRows; o++)
{
buttonCubes[menuRows*i + o] = GameObject.CreatePrimitive(PrimitiveType.Cube);//create cube
buttonCubes[menuRows*i + o].transform.localScale = new Vector3(1, 1, 0.1f);//flatten it
buttonCubes[menuRows*i + o].transform.position = new Vector3((i * 1.2f) - (0.1125f*(float)Math.Pow(menuColumns, 2)),(o * 1.2f) - (0.05625f*(float)Math.Pow(menuRows, 2)),-1);//move them
buttonCubes[menuRows*i + o].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/back") as Texture2D;//load texture
buttonPlanes[menuRows*i + o] = GameObject.CreatePrimitive(PrimitiveType.Plane);//create plane
buttonPlanes[menuRows*i + o].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);//shrink them
Quaternion q = new Quaternion(0, 0, 0, 1);//create rotation quaternion
q.SetLookRotation(new Vector3(0,-1000,-1), new Vector3(0,1,0));//assign values to quaternion
buttonPlanes[menuRows*i + o].transform.rotation = q;//assign quaternion to object
buttonPlanes[menuRows*i + o].transform.position = new Vector3((i * 1.2f) - (0.1125f*(float)Math.Pow(menuColumns, 2)),(o * 1.2f) - (0.05625f*(float)Math.Pow(menuRows, 2)),-1.051f);//move them
buttonCubes[menuRows*i + o].transform.parent = buttonPlanes[menuRows*i + o].transform;//make plane parent of cube
buttonPlanes[menuRows*i + o].GetComponent<Renderer>().material.shader = Shader.Find("Particles/Alpha Blended");//set shader
buttonCubes[menuRows*i + o].GetComponent<Renderer>().material.shader = Shader.Find("Particles/Alpha Blended");//set shader
Destroy(buttonPlanes[menuRows*i + o].GetComponent<Collider>());
buttonPlanes[menuRows*i + o].AddComponent<BoxCollider>();
Rigidbody gameObjectsRigidBody = buttonPlanes[menuRows*i + o].AddComponent<Rigidbody>(); // Add the rigidbody.
gameObjectsRigidBody.mass = 5;//set weight
gameObjectsRigidBody.useGravity = false;//disable gravity
buttonPlanes[menuRows*i + o].tag = "MenuItem";
}
}
buttonPlanes [0].name = "2x2";
buttonPlanes [0].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/Menu/2x2") as Texture2D;
buttonPlanes [1].name = "2x3";
buttonPlanes [1].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/Menu/2x3") as Texture2D;
buttonPlanes [2].name = "3x4";
buttonPlanes [2].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/Menu/3x4") as Texture2D;
buttonPlanes [3].name = "4x4";
buttonPlanes [3].GetComponent<Renderer>().material.mainTexture = Resources.Load("Textures/Menu/4x4") as Texture2D;
}
示例13: MoveAlongSpline
void MoveAlongSpline()
{
if (theSplineGenerator != null)
{
Vector3 newPosition = new Vector3(0,0,0);
Vector3 newUp = new Vector3(0,1,0);
Vector3 newForward = new Vector3(0,0,1);
Quaternion newOrientation = new Quaternion(0,0,0,1);
theSplineGenerator.GetPointAlongSpline(distMoved, out newPosition, out newUp, out newForward);
//print("MoveAlongSpline() - dist = " + distMoved + ", transform.position = " + transform.position + ", newPosition = " + newPosition);
transform.position = newPosition;
newOrientation.SetLookRotation(newForward, newUp);
transform.rotation = newOrientation;
Camera.main.transform.rotation = newOrientation;
}
}
示例14: reportLastMoveDirection
public void reportLastMoveDirection(Vector3 direction)
{
if (direction.magnitude > 0) {
Quaternion q = new Quaternion ();
q.SetLookRotation (direction);
var targetX = new Vector3(q.eulerAngles.y,0,0);
var sourceX = new Vector3(x, 0,0);
var stepX = Vector3.Slerp (sourceX, targetX,0.7f );
Debug.Log (sourceX.ToString() + targetX.ToString() + stepX.ToString());
x = stepX.x;
//x = q.eulerAngles.y;
}
}
示例15: Shoot
public void Shoot( GameObject projectile, GameObject target )
{
if( launchPos != null )
{
Vector3 vel = target.transform.position - launchPos.transform.position;
vel.Normalize();
vel *= launchSpeed;
Quaternion rot = new Quaternion();
rot.SetLookRotation(vel);
GameObject go = (GameObject)Instantiate( projectile, launchPos.transform.position, rot );
if( go.rigidbody != null )
{
go.rigidbody.velocity = vel;
}
}
else
{
Debug.Log("Try to launch a projectile without a launchPos being set");
}
}