Question by
DirtyDilara · May 30, 2021 at 03:52 PM ·
rotationplayermousefirst-person-controllermanual
[C# Scripting] Set the rotation of the player, when another script access it at the same time.
Hello what´s up Unity friends,
I came accross a weird sounding problem. I have a simple C# script which sets the rotation of my first person player camera.
public class PlayerLook : PlayerBase
{
[Header("Looking around")]
[SerializeField] float sensX = 15f;
[SerializeField] float sensY = 15f;
[SerializeField] float multiplier = 0.1f;
Vector3 rot;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
rot = transform.eulerAngles;
}
void Update()
{
rot.y += Mouse_X * sensX * multiplier * Time.deltaTime;
rot.x -= Mouse_Y * sensY * multiplier * Time.deltaTime;
rot.x = Mathf.Clamp(rot.x, -90f, 90f);
cam.transform.rotation = Quaternion.Euler(rot.x, rot.y, cam.transform.eulerAngles.z);
orientation.transform.rotation = Quaternion.Euler(0, rot.y, orientation.transform.eulerAngles.z);
}
public void SetRotation(Vector3 angles)
{
rot = angles;
}
}
In another script I manually want to set my player rotation:
...
//// make player look towards trolley
PlayerLook looker = player.GetComponent<PlayerLook>();
if (looker != null)
{
looker.SetRotation(playerPosition.eulerAngles);
}
else
{
fnc.cam.eulerAngles = playerPosition.eulerAngles;
}
...
With my SetRotation method I hopefully wanted to set the rotation also when the PlayerLook script is attached, but that doesnt work out..
You can also answer for more questions depending on my problem.
Any idea? :)
Best regards
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613034351im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
TopDown Look at mouse 0 Answers
Automatically flip a player game object upright on z axis? 1 Answer
Rotate player with mouse. 0 Answers
LookAt() not working? 2 Answers
How to make Rotation of HingeJoint2D constant via mouse button C# 1 Answer