I’m not sure If I understand what you are trying to do. If you are trying to do something similar to the game “Dead Nation”, then I would suggest something like this:
MouseLook.cs
void Update() { Vector3 mouse = Input.mousePosition; Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(new Vector3( mouse.x, mouse.y, player.transform.position.y)); Vector3 forward = mouseWorld - player.transform.position; player.transform.rotation = Quaternion.LookRotation(forward, Vector3.up); }
If you want the camera to move and rotate along with the player then just make the camera a child of the player object.
Related Posts:
- How to find child of a GameObject or the script attached to child GameObject via script
- Getting mouse position in unity
- How to make the script wait/sleep in a simple way in unity
- Unity OnTriggerEnter2D not registering
- OnCollisionEnter() not working in Unity3D
- Unity cannot convert from ‘string’ to ‘int’
- Can’t add script component because the script class cannot be found?
- Why should I use SerializeField?
- OnTriggerEnter not working at Unity3D
- How to jump in Unity 3d?
- Unity3d no Monobehaviour scripts in the file, or their names don’t match the file name
- Unity3d restart current scene
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Unity 2d jumping script
- OnCollisionEnter2D not being executed?
- Unity “The associated script can not be loaded” and “Win32Exception: The system cannot find the file specified”
- Error when Building Project: Error building Player because scripts have compile errors in the editor
- Unity3D. Trying to send command for object without authority
- Expression denotes a `type’, where a `variable’, `value’ or `method group’ was expected UNITY3D
- How to pass data (and references) between scenes in Unity
- Rotate object in Unity 3D
- OnCollisionEnter is not called in unity
- Unity 5.2.2 changing Visual Studio back to MonoDevelop
- “A namespace cannot directly contain members such as fields or methods”
- Unity – How to stop Play Mode in case of infinite loop?
- Unity Scripts edited in Visual studio don’t provide autocomplete
- Is there a keyboard shortcut to maximize the Game window in Unity in Play Mode?
- How to connect to database from Unity
- Convert HTML to PDF in .NET
- C# HttpClient An existing connection was forcibly closed by the remote host
- Can anyone explain IEnumerable and IEnumerator to me? [closed]
- IOException: The process cannot access the file ‘file path’ because it is being used by another process
- Error : Index was outside the bounds of the array.
- No connection could be made because the target machine actively refused it?
- What does a lock statement do under the hood?
- What is C# equivalent of
- C# 2D platformer movement code
- ASP.NET 5 MVC: unable to connect to web server ‘IIS Express’
- Why is this code throwing an InvalidOperationException?
- How to add a default Default.aspx to a ASP.NET Web Application Project?
- Regex for numbers only
- Access to the path is denied
- What does question mark and dot operator ?. mean in C# 6.0?
- The client and server cannot communicate, because they do not possess a common algorithm – ASP.NET C# IIS TLS 1.0 / 1.1 / 1.2 – Win32Exception
- ToList().ForEach in Linq
- Cannot implicitly convert type ‘customtype’ to ‘othercustomtype’
- Proper way to initialize a C# dictionary with values
- Get dictionary value by key
- Invalid URI: The format of the URI could not be determined
- How to add a delay in a C# unity script
- SQL Insert Query Using C#
- How to round up the result of integer division?
- Read and parse a Json File in C#
- Passing just a type as a parameter in C#
- The remote server returned an error: (407) Proxy Authentication Required
- IsNumeric function in c#
- How to declare session variable in C#?
- Cannot open database “test” requested by the login. The login failed. Login failed for user ‘xyz\ASPNET’
- Writing data into CSV file in C#
- System.Data.SqlClient.SqlException: Login failed for user
- C# Print list of string array
- finding the maximum length of lists in c#
- “A project with an Output type of Class Library cannot be started directly”
- Creating a comma separated list from IList
or IEnumerable - EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong
- Randomize a List
- “A project with an Output type of Class Library cannot be started directly”
- Conversion of a datetime2 data type to a datetime data type results out-of-range value
- JSON.NET Error Self referencing loop detected for type
- entity object cannot be referenced by multiple instances of IEntityChangeTracker. while adding related objects to entity in Entity Framework 4.1
- What does ModelState.IsValid do?
- When to use an Enum vs Struct
- How to make a simple popup box in Visual C#?
- windows could not start service on local computer error 5 access is denied
- Destroy an object in C#
- How can I implement static methods on an interface?
- How to add List<> to a List<> in asp.net [duplicate]
- Adding a newline into a string in C#
- How to format a string as a telephone number in C#
- How can we generate getters and setters in Visual Studio?
- .NET String.Format() to add commas in thousands place for a number
- Fastest way to generate a random boolean
- need implement C# Counter
- Invalid attempt to read when no data is present
- What is the simplest regular expression to validate emails to not accept them blindly?
- The provider did not return a ProviderManifestToken string Entity Framework
- Why is HttpContext.Current null?
- Getting selected value of a combobox
- How do I clone a generic list in C#?
- Is there a way to toggle a boolean variable in C#?
- Effectively use async/await with ASP.NET Web API
- A potentially dangerous Request.Path value was detected from the client (*)
- Get single listView SelectedItem
- .NET Core vs Mono
- Add item to Listview control
- Windows service start failure: Cannot start service from the command line or debugger [duplicate]
- Displaying DateTime picker instead of Date picker in ASP .NET MVC 5.1/HTML 5 specific
- member names cannot be the same as their enclosing type C#
- How to enumerate an enum