- Home /
Question by
maghamre · May 16 at 11:09 PM ·
prefabsvariablesgame development
Set variables from a prefab
So im working on respawning the player, but when i spawn in a player i have to set the variables for my cameraholder
again. In the following script below i want to set the variable orientation from my prefab Player
.
How do i do this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
public Transform camHolder;
float xRotation;
float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
orientation = GameObject.FindWithTag("orientation");
// get mouse input
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
// rotate cam and orientation
camHolder.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
public void DoFov(float endValue)
{
GetComponent<Camera>().DOFieldOfView(endValue, 0.25f);
}
public void DoTilt(float zTilt)
{
transform.DOLocalRotate(new Vector3(0, 0, zTilt), 0.25f);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613060636im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to instantiate an object from outside of unity project ?? 0 Answers
cant set object in prefab object, but can in the scene 1 Answer
Scripts/buttons getting old (prefab?) values of variables 1 Answer
How many variables can i have of type 'Prefab' in a scene at one time? 1 Answer
Increasing through a list after an object has been destroyed 2 Answers