本文整理汇总了C#中UnityEngine.Transform.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.Rotate方法的具体用法?C# Transform.Rotate怎么用?C# Transform.Rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.Rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(Context _context)
{
// action logic here
//if( context.target == null) return;
BaseContext context = (BaseContext) _context;
if(context.target == null) return;
if(context.animator != null) context.animator.SetFloat("Speed", 1);
transform = context.gameObject.transform;
frontRight = transform.TransformDirection( new Vector3( 0.2f, 0, 1));
frontLeft = transform.TransformDirection( new Vector3(-0.2f, 0, 1));
// forward = transform.TransformDirection(Vector3.forward);
heading = context.target.position - transform.position;
origin = transform.position + new Vector3(0, 0.5f, 0);
if(context.collision && Physics.Raycast(origin, frontRight, out hit, context.rayDistance, layerMask)){
if(hit.transform.gameObject.GetInstanceID() == context.target.gameObject.GetInstanceID()){
return;
}
else{
while(Physics.Raycast(origin, transform.forward, out hit, context.rayDistance, layerMask)){
// Debug.Log(hit.point);
transform.Rotate(0, -1, 0 );
}
transform.Translate(Vector3.forward * Time.deltaTime * context.speed );
}
}
else if(context.collision && Physics.Raycast(origin, frontLeft, out hit, context.rayDistance, layerMask)){
if(hit.transform.gameObject == context.target){
return;
}
else {
while(Physics.Raycast(origin, transform.forward, out hit, context.rayDistance, layerMask)){
// Debug.Log(hit.point);
transform.Rotate(0, 1, 0 );
}
transform.Translate(Vector3.forward * Time.deltaTime * context.speed );
}
}
// {
// context.rerouting = true;
// Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * context.rayDistance, Color.red);
// }
// else{
else {
context.rerouting = false;
//heading.y += offset.Value.y;
distance = heading.magnitude;
if(distance > 0.1)
{
heading = heading/distance;
transform.Translate(heading * context.speed * Time.deltaTime, Space.World);
}
}
Debug.DrawRay(origin, frontRight*context.rayDistance, Color.green);
Debug.DrawRay(origin, frontLeft*context.rayDistance, Color.blue);
}
示例2: RotateHelper
public RotateHelper(GameObject obj, Vector3 rotation, float speed)
{
from = obj.transform;
from.Rotate(rotation);
to = new Quaternion(from.rotation.x, from.rotation.y, from.rotation.z, from.rotation.w);
from.Rotate(-rotation.x, -rotation.y, -rotation.z);
this.speed = speed;
this.obj = obj;
}
示例3: ExecuteCamera
protected override void ExecuteCamera(Transform target)
{
if(target)
{
if(this.lockCursor)
{
Screen.lockCursor = true;
}
float rotX = ControlHandler.GetAxis(this.horizontalAxis)*this.sensitivity.x;
float rotY = ControlHandler.GetAxis(this.verticalAxis)*this.sensitivity.y;
// X on player
target.Rotate(0, rotX, 0);
// Y on camera
Vector3 tmp = this.transform.eulerAngles;
tmp.y = target.eulerAngles.y;
tmp.z = 0;
tmp.x -= rotY;
this.transform.eulerAngles = tmp;
if(this.onChild != "")
{
Transform t = target.Find(this.onChild);
if(t != null) target = t;
}
this.transform.position = target.position+target.TransformDirection(this.offset);
}
}
示例4: Action
public override void Action(Transform p_Actor)
{
if (m_Rigidbody == null)
m_Rigidbody = p_Actor.GetComponent<Rigidbody>();
//todo: save this to stop getting the ref every frame
bool grounded = p_Actor.GetComponent<Civilian>().IsGrounded();
///p_Actor.rotation = Quaternion.Euler(new Vector3(0f, p_Actor.rotation.eulerAngles.y, p_Actor.rotation.eulerAngles.z));
//Debug.Log (p_Actor.rotation);
//keep jumping
if (!grounded)
{
m_Rigidbody.velocity += Vector3.down * Time.deltaTime * PlayerController.Instance.m_FallSpeed;
p_Actor.Rotate(Vector3.up, 20.0f);
}
else
{
m_ElapsedTimeGround += Time.deltaTime;
if (m_ElapsedTimeGround > m_MaxTimeLanded)
{
m_Rigidbody.velocity = Vector3.up*3f;
m_ElapsedTimeGround = UnityEngine.Random.Range(0.0f, m_MaxTimeLanded);
}
}
}
示例5: UpdateView
public override void UpdateView(Transform t)
{
float ySens = sensitivityY;
if (invertY) { ySens *= -1f; }
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = t.localEulerAngles.y + GetMouseX() * sensitivityX;
rotationY += GetMouseY() * ySens;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
t.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
t.Rotate(0, GetMouseX() * sensitivityX, 0);
}
else
{
rotationY += GetMouseY() * ySens;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
t.localEulerAngles = new Vector3(-rotationY, t.localEulerAngles.y, 0);
}
}
示例6: Start
void Start()
{
transform = GetComponent<Transform> ();
player = GameObject.FindGameObjectWithTag ("Player").GetComponent<Transform> ();
transform.Rotate (new Vector3 (0, 0, 78));
transform.SetParent (player);
}
示例7: RotatePlier
IEnumerator RotatePlier(Transform target, int count, float rotationAmount)
{
int i = 0;
while (i < count * 2)
{
i++;
if( i > count )
{
target.Rotate(new Vector3(0, 0, -rotationAmount));
}
else
{
target.Rotate(new Vector3(0, 0, rotationAmount));
}
yield return null;
}
}
示例8: ApplyRotationFlip
public static void ApplyRotationFlip(Transform transform, float rotation, bool flipX, bool flipY)
{
transform.Rotate(0, 0, rotation);
Vector3 s = transform.localScale;
float flipXFactor = flipX ? -1 : 1;
float flipYFactor = flipY ? -1 : 1;
transform.localScale = new Vector3(s.x * flipXFactor, s.y * flipYFactor, s.z);
}
示例9: InitializeMotion
public void InitializeMotion(Vector2 motion)
{
vel = new Vector3(motion.x, motion.y);
pictureTrans = GetComponentInChildren<SpriteRenderer>().transform;
pictureTrans.Rotate(Vector3.forward, Random.Range(0f, 360f));
myRollAngle = Random.Range (0,2) == 0 ? Random.Range(-1f, -.5f) : Random.Range (.5f, 1f);
}
示例10: PositionOn
public static bool PositionOn(Transform transform, Transform target, Vector3 direction, float maxDistance, bool setNewRotation, Vector3 newRotation, bool randomYRotation, float height = 0, Transform parentTo = null)
{
Vector3 raycastDir;
if (direction != Vector3.zero) {
raycastDir = direction;
} else {
if (target != null) {
raycastDir = target.position - transform.position;
} else {
raycastDir = Vector3.down;
}
}
if (Physics.Raycast(transform.position - raycastDir * 0.01f, raycastDir, maxDistance)) {
// instead of this, find better way to reposition stuff.
RaycastHit[] rg = Physics.RaycastAll(transform.position, raycastDir, 500);
if (rg.Any(r => r.transform == target) || target == null) {
RaycastHit objHit;
if (target != null) {
objHit = rg.First(r => r.transform == target);
} else {
objHit = rg.OrderBy(rh => (rh.point - transform.position).sqrMagnitude).First();
}
if (setNewRotation) {
transform.rotation = Quaternion.Euler(newRotation);
} else {
// rotate so it is looking towards normal of intersection with target
transform.rotation = LookAtWithY(objHit.normal);// *Quaternion.Euler(0, 90, 0);
}
if (randomYRotation) {
transform.Rotate(0, Random.Range(0, 360f), 0);
}
if (height != 0) {
// move over to target
EaseTo(transform, objHit.point + raycastDir.normalized * height);
} else {
EaseTo(transform, objHit.point);
}
//transform.position = rg.First(r => r.transform.tag == "Terrain").point;
} else {
return false;
}
} else {
return false;
}
if (parentTo != null) {
transform.parent = parentTo;
}
return true;
}
示例11: Initialize
public void Initialize(Transform axis, float accelerationSpeed, float maxSpeed, Vector3 rotationAxis)
{
this.axis = axis;
this.accelerationSpeed = accelerationSpeed;
this.maxSpeed = maxSpeed;
this.setRotationAxis(rotationAxis);
this.setInitialRotation(axis.localRotation);
axis.Rotate(rotationAxis, this.currentRotation);
}
示例12: ChooseManeuver
//Choose the Maneuver the ship will take
public ManeuverType ChooseManeuver(Transform player)
{
if (Input.GetButton("LeftMan"))
{
//Save coordinates
start = player;
end = player;
loopCount = 0;
//Return Maneuver Type
return ManeuverType.L_DODGE;
}
else if (Input.GetButton("RightMan"))
{
//Save coordinates
start = player;
end = player;
loopCount = 0;
//Return Maneuver Type
return ManeuverType.R_DODGE;
}
else if (Input.GetButton("DownMan"))
{
//Save coordinates
start = player;
player.Rotate(Vector3.left * 180);
end = player;
player.Rotate(Vector3.left * 180);
//Return Maneuver Type
return ManeuverType.U_TURN1;
}
else if (Input.GetButton("UpMan"))
{
//Save coordinates
start = player;
end = player;
loopCount = 0;
//Return Maneuver Type
return ManeuverType.LOOP;
}
else
return ManeuverType.NONE;
}
示例13: Awake
void Awake()
{
transform = GetComponent<Transform> ();
rigidbody = GetComponent<Rigidbody2D> ();
// start at mouse click
transform.position = Camera.main.ScreenToWorldPoint (Input.mousePosition);
transform.position = new Vector3 (transform.position.x, transform.position.y, 0f);
// randomly rotate and move back (off screen)
transform.Rotate (0f, 0f, Random.Range(0f,360f));
transform.Translate (Vector3.down * spawnDistance);
}
示例14: OnStart
//private bool showMenu = false;
//private Rect windowRect = new Rect(500f, 250f, 250f, 50f);
//private FSGUIPopup popup;
public override void OnStart(PartModule.StartState state)
{
debug.debugMode = debugMode;
engine = new FSengineWrapper(part);
if (engine.type != FSengineWrapper.EngineType.NONE)
{
//Debug.Log("FSswitchEngineThrustTransform: Engine module found");
thrustTransform = part.FindModelTransform(defaultTTName);
defaultTT = new GameObject().transform;
defaultTT.localPosition = thrustTransform.localPosition;
defaultTT.localRotation = thrustTransform.localRotation;
//defaultTT = part.FindModelTransform(defaultTTName);
if (useNamedAlternate == 1)
{
debug.debugMessage("Finding alternate TT");
alternateTT = part.FindModelTransform(alternateTTName);
if (alternateTT == null) debug.debugMessage("Did not find alternate TT " + alternateTTName);
}
else
{
debug.debugMessage("Using flipped default TT as reverse");
alternateTT = new GameObject().transform;
alternateTT.localPosition = defaultTT.localPosition;
alternateTT.localRotation = defaultTT.localRotation;
alternateTT.Rotate(alternateTT.right, 180f);
}
if (defaultTT == null || alternateTT == null) valid = false;
if (isReversed)
{
setTTReverseState(true);
}
else
{
setTTReverseState(false);
}
}
else
{
valid = false;
Debug.Log("FSswitchEngineThrustTransform: no engine module found");
}
animateThrottle = part.Modules.OfType<FSanimateThrottle>().FirstOrDefault();
if (animateThrottle != null)
{
animateThrottle.modeList.Add(new mode(animateThrottleRange.x, animateThrottleRange.y));
animateThrottleMode = animateThrottle.modeList.Count - 1;
}
}
示例15: lockToEdge
public void lockToEdge(Transform newElement)
{
float screenX;
float screenY;
switch(newElement.name) {
case "LowerLeft" :
screenX = 0.0f;
screenY = 0.0f;
break;
case "LowerRight" :
screenX = Screen.width;
screenY = 0.0f;
break;
case "LowerCenter" :
screenX = Screen.width * 0.5f;
screenY = 0.0f;
break;
case "UpperRight" :
screenX = Screen.width;
screenY = Screen.height;
break;
case "UpperCenter" :
screenX = Screen.width * 0.5f;
screenY = Screen.height;
break;
case "UpperLeft" :
screenX = 0.0f;
screenY = Screen.height;
break;
case "Center" :
screenX = Screen.width * 0.5f;
screenY = Screen.height * 0.5f;
break;
default :
screenX = Screen.width * 0.5f;
screenY = Screen.width * 0.5f;
break;
}
//move element into position
newElement.position = Camera.main.ScreenToWorldPoint(new Vector3 (screenX, screenY, Camera.main.nearClipPlane + 1));
newElement.rotation = Camera.main.transform.rotation;
newElement.Rotate(0.0f, 180.0f, 0.0f);
newElement.localScale = new Vector3(UIScale, UIScale, UIScale);
}