- Home /
Why are my scripts not working after I opened project in newer version?,Project Scripts broken after opening project in newer version
I opened my project in 2019.2.15 instead of 2018.4.13, not my scripts arent working properly.
-my player isnt moving in the camera's direction . -My camera won't pivot in the vertical around my player.
Please help!
Code:
public class CameraMovement : MonoBehaviour {
public float rotateSpeed;
public Transform player;
public Vector3 offset;
public Transform PivotPoint;
public float maxCamAngle;
public float minCamAngle;
public int invertYaxis; // set this to any negative or positive value *****************************************
// Start is called before the first frame update
void Start()
{
offset = player.position - transform.position;
PivotPoint.transform.position = player.transform.position;
PivotPoint.transform.parent = player.transform;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void LateUpdate()
{
//Sets the angle of the camera according to the rotation of the player in X axis
float rightXAngle = PivotPoint.eulerAngles.x;
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
player.Rotate(0, horizontal, 0);
//Sets the angle of the camera according to the rotation of the player in Y axis
float rightYAngle = player.eulerAngles.y;
float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
PivotPoint.Rotate(vertical, 0, 0);
//Sets Camera LOCATION according to pivot of the player
Quaternion rotation = Quaternion.Euler(rightXAngle, rightYAngle, 0);
transform.position = player.position - (rotation * offset);
//Makes it so that camera doesnt clip through the ground and gets closer
if(transform.position.y < player.position.y) {
transform.position = new Vector3(transform.position.x, player.position.y -0.01f, transform.position.z);
}
//stop camera from turning 360 degrees in axis
if( PivotPoint.rotation.eulerAngles.x > maxCamAngle && PivotPoint.rotation.eulerAngles.x <100f) {
PivotPoint.rotation = Quaternion.Euler(maxCamAngle ,0,0);
}
if(PivotPoint.rotation.eulerAngles.x > 180 && PivotPoint.rotation.eulerAngles.x < 360f - minCamAngle) {
PivotPoint.rotation = Quaternion.Euler(360f - minCamAngle,0 ,0);
}
//centers Camera
transform.LookAt(player);
}
}
and
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public Rigidbody RB;
public float jumpForce;
public CharacterController controller;
private Vector3 moveDirection;
public float gravityScale;
public float windUpTimeLow;
public float windUpTimeMedium;
public float windUpTimeHigh;
float startTimer;
public Material green;
public Material orange;
public Material red;
void Start() {
controller = GetComponent<CharacterController>();
Debug.Log("Game Has Started");
}
// Update is called once per frame
void Update() {
float yStore = moveDirection.y;
moveDirection = (transform.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime) + (transform.right * Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime);
moveDirection.y = yStore;
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime);
controller.Move(moveDirection * Time.deltaTime);
if(moveDirection.y > 0f) {
startTimer = 0f;
GetComponent<Renderer>().material = green;
}
//makes the player wind up his jump according to the time he held space
if(controller.isGrounded) {
if(Input.GetButtonDown("Jump")) {
startTimer= Time.time;
}
if(Input.GetButtonUp("Jump") && Time.time - startTimer <= windUpTimeLow) {
Debug.Log(startTimer);
moveDirection.y = 1.5f * jumpForce;
}
if(Input.GetButtonUp("Jump") && windUpTimeLow < Time.time - startTimer && Time.time - startTimer <= windUpTimeMedium) {
Debug.Log(startTimer);
moveDirection.y = 2f * jumpForce;
}
if(Input.GetButtonUp("Jump") && Time.time - startTimer >= windUpTimeHigh) {
Debug.Log(startTimer);
moveDirection.y = 2.5f * jumpForce;
}
if(windUpTimeLow < Time.time - startTimer && Time.time - startTimer <= windUpTimeMedium && startTimer > 0f) {
GetComponent<Renderer>().material = orange;
}
if(windUpTimeMedium < Time.time - startTimer && Time.time - startTimer <= windUpTimeHigh && startTimer > 0f) {
GetComponent<Renderer>().material = red;
}
}
} }
$$anonymous$$y first guess is, the console tells you. $$anonymous$$y second is, the Input $$anonymous$$anager either changed or what you're using as axis and button strings is not setup in the manager anymore.
Answer by sherry_f · Dec 16, 2019 at 11:55 PM
It would help if you look for deprecated API in the documentation. Maybe either of these link could be a good starting point : https://unity3d.com/unity/whats-new/2019.2.15 https://docs.unity3d.com/ScriptReference/Transform.html