Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

How do I fix error CS1656 with my playerprefs

$
0
0
In my game I want the player to play through the "story" section of my game before they are allowed to do a different game mode. In my scripts I made a playerprefs that changes itself to a value of 1 when you finish the last level. On my title screen I have a button that is supposed to be enabled if the value of the playerprefs is 1 or not and if it isn't 1 the button is disabled. When I tested this out I got the Error CS1656. Here are my Scripts: Script 1: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerCollisionFinal : MonoBehaviour { public PlayerMovement movement; public float collisionForce = 500f; public Rigidbody player; private int setAllow = 0; void OnCollisionEnter(Collision collisionInfo) { if (collisionInfo.collider.tag == "Obstacle") { Debug.Log("We hit an obstacle"); movement.enabled = false; player.AddForce(0, collisionForce, -collisionForce); FindObjectOfType().EndGame(); } if (collisionInfo.collider.tag == "End") { setAllow = 1; PlayerPrefs.SetInt("SetAllow", setAllow); } } } Script 2: using System.Collections; using System.Collections.Generic; using UnityEngine; public class DetectAllow : MonoBehaviour { public GameObject unlimited; public GameObject soundtrack; private int detectAllow = PlayerPrefs.GetInt("SetAllow"); void Start() { if(detectAllow == 1) { unlimited.SetActive = true; soundtrack.SetActive = true; } else { unlimited.SetActive = false; soundtrack.SetActive = false; } } } If anyone can give me some advice I would really appreciate it.

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>