Понедельник, 16 Мая 2022, 19:06

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 2
  • 1
  • 2
  • »
Модератор форума: beril  
Форум игроделов » Движки для разработки игр и сложные системы разработки » Unity » Скриптирование (С#,java итд)
Скриптирование
Leon510Дата: Вторник, 11 Марта 2014, 14:33 | Сообщение # 1
был не раз
Сейчас нет на сайте
Ребят,помогите с сохранением player prefs.
Нужно в главном игровом скрипте сделать сохранение и загрузку текстовых данных (рекорд) любым способом,но лучше в файл.
И при загрузке игры,нужно сделать считывание числа (рекорда) из файла...итд итп.
Короче помогите ПОЖАЛУЙСТА!!!
Вот скрипт:
Код

using UnityEngine;
using System.Collections.Generic;

public class Game : MonoBehaviour {

public Transform redBuilding;
public Transform greenBuilding;
public Transform avatar;
public Rigidbody avatarRigidBody;
public MeshRenderer avatarMeshRenderer;
public TrailRenderer avatarTrailRenderer;
public Rigidbody avatarDebris;
public Material redMaterial;
public Material greenMaterial;
public Transform oldBackgroundBuildings;
public Transform newBackgroundBuildings;
public GUIText distanceLabel;
public GUIText highscoreLabel;
public GUITexture fullscreenOverlayTexture;
public AudioClip[] jumpAudioClips;
public AudioClip[] hitAudioClips;
public AudioClip failAudioClip;

// Private
const int kMaxBlockBuildings = 50;
const float kMinBlockWidth = 60;
const float kStartAvatarSpeed = 8.0f;
const float kAvatarSpeedIncCoef = 0.05f;
const float kMaxAvatarSpeed = 11.0f;
const float kGravity = 30.0f;
const float kBounciness = 0.2f;
const float kJumpEnergyDeplitionRate = 1.0f;
const float kStartingJumpEnergy = 0.8f;
const float kJumpEnergyEfficiencyCoef = 50.5f;
const float kJumpRotationTime = 0.4f;
const float kMinJumpImpulse = 4.0f;
const float kCameraFriction = 0.7f;
const float kHardestMinBuildingWidth = 4.0f;
const float kHardestMaxBuildingWidth = 16.0f;
const float kHardestMaxSpaceWidth = 3.5f;
const float kFadeToMenuTime = 0.7f;
const float kMinBuildingGround = -15.0f;
const float kMaxBuildingGround = 5.0f;
const float kHardestMaxBuildingGroundDifference = 1.2f;

private Touch myTouch;
private Touch myTouch2;
public GUITexture jump;
public GUITexture color;
private bool touchFlag = false;

// Local
Transform transformRef;

enum ElementColor {
Red,
Green,
}

Vector3 cameraVelocity;

// Blocks
Transform[] oldBlockBuildings;
ElementColor[] oldBlockBuildingColors;
int numberOfOldBlockBuildings;
Transform[] actualBlockBuildings;
ElementColor[] actualBlockBuildingColors;
int numberOfActualBlockBuildings;

int activeBuildingIndex;
int activeBlockIndex;

float actualBlockOffset;
float actualBlockWidth;
float actualBlockMinBuildingWidth;
float actualBlockMaxBuildingWidth;
float actualBlockMinSpaceWidth;
float actualBlockMaxSpaceWidth;
float actualBlockMaxBuildingGroundDifference;
float lastBuildingGround;

float jumpEnergy;
bool readyForNextJump;

// Avatar
float avatarYVelocity;
bool avatarHasContactWithGround;
ElementColor avatarColor;
float jumpRotationTimer;
float avatarSpeed;

// Menu
float fadeToMenuTimer;
int highscore;
int prevRunDistance;
int prevHighscore;

// Game states
enum GameState {
Playing,
FadeToMenu,
Menu,
};

GameState gameState;

// Use this for initialization
void Start () {

transformRef = transform;

oldBlockBuildings = new Transform[kMaxBlockBuildings];
actualBlockBuildings = new Transform[kMaxBlockBuildings];
oldBlockBuildingColors = new ElementColor[kMaxBlockBuildings];
actualBlockBuildingColors = new ElementColor[kMaxBlockBuildings];

ResetGame();
}

//static int screenshotCount = 0;

// Update is called once per frame
void Update () {

/*
// take screenshot on up->down transition of F9 key
if (Input.GetKeyDown("f9"))
{
string screenshotFilename;
do
{
screenshotCount++;
screenshotFilename = "screenshot" + screenshotCount + ".png";

} while (System.IO.File.Exists(screenshotFilename));

Application.CaptureScreenshot(screenshotFilename);
}
*/

// New blocks

if (avatar.position.x > actualBlockOffset + actualBlockBuildings[0].localScale.x)
{
CreateNewBlock();
}

if (gameState == GameState.Playing)
{

if (Input.touchCount > 0)
{
myTouch = Input.GetTouch(0);

if ((jump.guiTexture.HitTest(myTouch.position)) && avatarHasContactWithGround && readyForNextJump && (myTouch.phase == TouchPhase.Began))
{
Jump();
}
if ((jump.guiTexture.HitTest(myTouch.position)) && (myTouch.phase == TouchPhase.Ended))
{
jumpEnergy = 0.0f;
readyForNextJump = true;
}
if (Input.touchCount == 2)
{
myTouch2 = Input.GetTouch(1);
if ((color.guiTexture.HitTest(myTouch2.position)) && (myTouch2.phase == TouchPhase.Began))
{
if (avatarColor == ElementColor.Green)
{
avatarMeshRenderer.material = redMaterial;
avatarTrailRenderer.material = redMaterial;
avatarColor = ElementColor.Red;
}
else
{
avatarMeshRenderer.material = greenMaterial;
avatarTrailRenderer.material = greenMaterial;
avatarColor = ElementColor.Green;
}
}
}
else if (Input.touchCount == 1)
{
myTouch2 = Input.GetTouch(0);
if ((color.guiTexture.HitTest(myTouch2.position)) && (myTouch2.phase == TouchPhase.Began))
{
if (avatarColor == ElementColor.Green)
{
avatarMeshRenderer.material = redMaterial;
avatarTrailRenderer.material = redMaterial;
avatarColor = ElementColor.Red;
}
else
{
avatarMeshRenderer.material = greenMaterial;
avatarTrailRenderer.material = greenMaterial;
avatarColor = ElementColor.Green;
}
}
}
}
}

/*
// Controlling game
if (gameState == GameState.Playing) {

// Jump
if (Input.GetButtonDown("jump") && avatarHasContactWithGround && readyForNextJump) {
Jump();
}
if (Input.GetButtonUp("jump")) {
jumpEnergy = 0.0f;
readyForNextJump = true;
}

// Switch
if (Input.GetButtonDown("switch")) {
if (avatarColor == ElementColor.Green) {
avatarMeshRenderer.material = redMaterial;
avatarTrailRenderer.material = redMaterial;
avatarColor = ElementColor.Red;
}
else {
avatarMeshRenderer.material = greenMaterial;
avatarTrailRenderer.material = greenMaterial;
avatarColor = ElementColor.Green;
}
}
}
*/

else if (gameState == GameState.FadeToMenu) {

fullscreenOverlayTexture.color = new Color(0.5f, 0.5f, 0.5f, 0.5f * fadeToMenuTimer / kFadeToMenuTime);

fadeToMenuTimer += Time.deltaTime;
if (fadeToMenuTimer >= kFadeToMenuTime) {
gameState = GameState.Menu;
fullscreenOverlayTexture.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
avatarRigidBody.isKinematic = true;
}
}
else if (gameState == GameState.Menu) {
if (Input.anyKeyDown) {
ResetGame();
}
}

// GUI data
int runDistance = Mathf.RoundToInt(avatar.position.x * 0.5f);
if (highscore < runDistance) {
highscore = runDistance;
}
if (prevRunDistance != runDistance) {
distanceLabel.text = System.Convert.ToString(runDistance);
prevRunDistance = runDistance;
}

if (prevHighscore != highscore) {
highscoreLabel.text = "Highscore:" + System.Convert.ToString(highscore);
prevHighscore = highscore;
}
}

void FixedUpdate()
{

// Camera pos
Vector3 cameraPosition = transformRef.position;
Vector3 designatedPosition = new Vector3(avatar.position.x + 3.5f, avatar.position.y + 0.2f, cameraPosition.z);
cameraVelocity += (designatedPosition - cameraPosition) * Time.deltaTime * 10.0f;
cameraVelocity *= kCameraFriction;
cameraPosition += cameraVelocity * Time.deltaTime * 10.0f;
cameraPosition.x = avatar.position.x + 3.4f;
transformRef.position = cameraPosition;

// Avatar physics
if (gameState == GameState.Playing)
{

// Avatar speed
if (avatarSpeed < kMaxAvatarSpeed)
{
avatarSpeed += kAvatarSpeedIncCoef * Time.deltaTime;
if (avatarSpeed > kMaxAvatarSpeed)
{
avatarSpeed = kMaxAvatarSpeed;
}
}

// Jumping

if (jump.guiTexture.HitTest(myTouch.position) && jumpEnergy > 0 && (myTouch.phase == TouchPhase.Stationary))
{
avatarYVelocity += jumpEnergy * kJumpEnergyEfficiencyCoef * Time.deltaTime;
jumpEnergy -= kJumpEnergyDeplitionRate * Time.deltaTime;
}

bool potentialFailCollision = (!IsAvatarInActiveBuildingColumn() && (avatar.position.y - avatar.localScale.y * 0.5f < GetNextBuildingGroundPosition()));

avatarYVelocity -= kGravity * Time.deltaTime;

Vector3 position = avatar.position;
Vector3 prevPosition = position;
position.x += Time.deltaTime * avatarSpeed;
position.y += Time.deltaTime * avatarYVelocity;
avatar.position = position;

// Rotation
if (!avatarHasContactWithGround && jumpRotationTimer < kJumpRotationTime)
{
float t = Mathf.Sin(jumpRotationTimer / kJumpRotationTime * Mathf.PI);
Quaternion rotation = avatar.rotation;
rotation.z = -t * Mathf.PI * 0.15f;
avatar.rotation = rotation;
jumpRotationTimer += Time.deltaTime;
}
else
{
Quaternion rotation = avatar.rotation;
rotation.z = 0.0f;
avatar.rotation = rotation;
}

float groundPosition = GetActiveBuildingGroundPosition();
if (IsAvatarInActiveBuildingColumn())
{

if (position.y - avatar.localScale.y * 0.5f < groundPosition)
{

if (!avatarHasContactWithGround)
{
AudioSource.PlayClipAtPoint(hitAudioClips[Random.Range(0, hitAudioClips.Length)], avatar.position);
}

avatarHasContactWithGround = true;
jumpRotationTimer = kJumpRotationTime;

// Fail
if (potentialFailCollision || GetActiveBuildingColor() != avatarColor)
{
FadeToMenu();
avatar.position = prevPosition;
avatarRigidBody.isKinematic = false;
avatarRigidBody.AddForce(new Vector3(avatarSpeed * 40.0f, avatarYVelocity * 20.0f, 0.0f));
AudioSource.PlayClipAtPoint(failAudioClip, avatar.position);
CreateFailDebris();
}
// Bounce
else
{
jumpEnergy = 0;
if (avatarYVelocity < 0)
{
avatarYVelocity = -avatarYVelocity * kBounciness;
}
position.y = groundPosition + avatar.localScale.y * 0.5f;
avatar.position = position;
}

if (jump.guiTexture.HitTest(myTouch.position) && readyForNextJump && (myTouch.phase == TouchPhase.Stationary))
{
Jump();
}
}
}
else
{
avatarHasContactWithGround = false;
}
}
}

void FadeToMenu() {

gameState = GameState.FadeToMenu;
fullscreenOverlayTexture.enabled = true;
fullscreenOverlayTexture.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
fadeToMenuTimer = 0;
}

void ResetGame() {

fullscreenOverlayTexture.enabled = false;

actualBlockOffset = 0;
actualBlockWidth = 0;
activeBuildingIndex = 0;
activeBlockIndex = 0;

actualBlockMinBuildingWidth = 18;
actualBlockMaxBuildingWidth = 20;
actualBlockMinSpaceWidth = 1.4f;
actualBlockMaxSpaceWidth = 1.6f;
actualBlockMaxBuildingGroundDifference = 0.5f;
lastBuildingGround = 0.0f;

CreateNewBlock();
CreateNewBlock();

avatarColor = oldBlockBuildingColors[0];
if (avatarColor == ElementColor.Green) {
avatarMeshRenderer.material = greenMaterial;
avatarTrailRenderer.material = greenMaterial;
}
else {
avatarMeshRenderer.material = redMaterial;
avatarTrailRenderer.material = redMaterial;
}

avatarSpeed = kStartAvatarSpeed;
jumpEnergy = kStartingJumpEnergy;
readyForNextJump = true;

avatarRigidBody.isKinematic = true;
avatar.transform.rotation = Quaternion.identity;
avatar.position = new Vector3(1.0f, 1.5f, 0.0f);

transform.position = new Vector3(8.0f, 1.2f, -30.0f);

gameState = GameState.Playing;
}

void Jump() {
jumpEnergy = kStartingJumpEnergy;
avatarHasContactWithGround = false;
jumpRotationTimer = 0;
avatarYVelocity += kMinJumpImpulse;
readyForNextJump = false;
AudioSource.PlayClipAtPoint(jumpAudioClips[Random.Range(0, jumpAudioClips.Length)], avatar.position);
}

void CreateNewBlock() {

// Switch BG
Transform bgBuildings = oldBackgroundBuildings;
oldBackgroundBuildings = newBackgroundBuildings;
newBackgroundBuildings = bgBuildings;

// Update active building index
if (activeBuildingIndex >= numberOfOldBlockBuildings) {
activeBuildingIndex -= numberOfOldBlockBuildings;
}
// Delete objects in old block
for (int i = 0; i < kMaxBlockBuildings; i++) {
if (oldBlockBuildings[i]) {
Destroy(oldBlockBuildings[i].gameObject);
oldBlockBuildings[i] = null;
}
}

System.Array.Copy(actualBlockBuildings, oldBlockBuildings, numberOfActualBlockBuildings);
System.Array.Copy(actualBlockBuildingColors, oldBlockBuildingColors, numberOfActualBlockBuildings);
numberOfOldBlockBuildings = numberOfActualBlockBuildings;
numberOfActualBlockBuildings = 0;

// New params
if (actualBlockMinBuildingWidth > kHardestMinBuildingWidth) {
actualBlockMinBuildingWidth -= 2.0f;
if (actualBlockMinBuildingWidth < kHardestMinBuildingWidth) {
actualBlockMinBuildingWidth = kHardestMinBuildingWidth;
}
}

if (actualBlockMaxBuildingWidth > kHardestMaxBuildingWidth) {
actualBlockMaxBuildingWidth -= 2.0f;
if (actualBlockMaxBuildingWidth < kHardestMaxBuildingWidth) {
actualBlockMaxBuildingWidth = kHardestMaxBuildingWidth;
}
}

if (actualBlockMaxSpaceWidth < kHardestMaxSpaceWidth) {
actualBlockMaxSpaceWidth += 0.5f;
if (actualBlockMaxSpaceWidth > kHardestMaxSpaceWidth) {
actualBlockMaxSpaceWidth = kHardestMaxSpaceWidth;
}
}

if (actualBlockMaxBuildingGroundDifference < kHardestMaxBuildingGroundDifference) {
actualBlockMaxBuildingGroundDifference += 0.1f;
if (actualBlockMaxBuildingGroundDifference > kHardestMaxBuildingGroundDifference) {
actualBlockMaxBuildingGroundDifference = kHardestMaxBuildingGroundDifference;
}
}

actualBlockOffset += actualBlockWidth;
float offset = actualBlockOffset;
actualBlockWidth = 0;

bool creatingSpace = true;
while (actualBlockWidth < kMinBlockWidth || !creatingSpace) {

// Space
if (creatingSpace) {
float spaceWidth = Random.Range(actualBlockMinSpaceWidth, actualBlockMaxSpaceWidth);
offset += spaceWidth;
actualBlockWidth += spaceWidth;
}
// Building
else {
if (numberOfActualBlockBuildings == kMaxBlockBuildings - 1) {
break;
}
else {
float buildingWidth = Random.Range(actualBlockMinBuildingWidth, actualBlockMaxBuildingWidth);

if (activeBlockIndex % 4 == 0) {
lastBuildingGround += actualBlockMaxBuildingGroundDifference * 0.3f;
buildingWidth = actualBlockMinBuildingWidth * 1.2f;
}
else if ((activeBlockIndex - 2) % 4 == 0 && activeBlockIndex > 4) {
lastBuildingGround -= actualBlockMaxBuildingGroundDifference * 0.2f;
buildingWidth = actualBlockMinBuildingWidth * 1.7f;
}
else {
lastBuildingGround += Random.Range(-actualBlockMaxBuildingGroundDifference, actualBlockMaxBuildingGroundDifference);
}

if (lastBuildingGround < kMinBuildingGround) {
lastBuildingGround = kMinBuildingGround;
}
else if (lastBuildingGround > kMaxBuildingGround) {
lastBuildingGround = kMaxBuildingGround;
}

ElementColor color = (Random.Range(0, 2) == 0) ? ElementColor.Red : ElementColor.Green;
Transform building = (color == ElementColor.Red ? redBuilding : greenBuilding);
Transform newBuilding = (Transform)Instantiate(building, new Vector3((offset + buildingWidth * 0.5f), lastBuildingGround - 25.0f, 0.0f), Quaternion.identity);
newBuilding.transform.localScale = new Vector3(buildingWidth, 50.0f, 0.2f);
actualBlockBuildings[numberOfActualBlockBuildings] = newBuilding;
actualBlockBuildingColors[numberOfActualBlockBuildings] = color;
numberOfActualBlockBuildings++;
offset += buildingWidth;
actualBlockWidth += buildingWidth;
}
}

creatingSpace = !creatingSpace;
}

Vector3 bgBuildingsPos = newBackgroundBuildings.position;
bgBuildingsPos.x = actualBlockOffset + actualBlockWidth * 0.5f;
newBackgroundBuildings.position = bgBuildingsPos;

Vector3 bgBuildingsScale = newBackgroundBuildings.localScale;
bgBuildingsScale.x = actualBlockWidth;
newBackgroundBuildings.localScale = bgBuildingsScale;

activeBlockIndex++;
}

void CreateFailDebris() {
for (int i = 0; i < 30; i++) {
Vector3 pos = Random.onUnitSphere * 0.2f + avatar.position;
Rigidbody debris = (Rigidbody)Instantiate(avatarDebris, pos, Quaternion.identity);
debris.AddForce(new Vector3(avatarSpeed * 40.0f, avatarYVelocity * 20.0f, 0.0f));
MeshRenderer debrisMeshRenderer = debris.GetComponent<MeshRenderer>();
if (avatarColor == ElementColor.Green) {
debrisMeshRenderer.material = greenMaterial;
}
else {
debrisMeshRenderer.material = redMaterial;
}
}
}

Transform GetBuildingForIdx(int buildingIdx) {

if (buildingIdx < numberOfOldBlockBuildings) {
return oldBlockBuildings[buildingIdx];
}
else {
return actualBlockBuildings[buildingIdx - numberOfOldBlockBuildings];
}
}

ElementColor GetBuildingColorForIdx(int buildingIdx) {
if (buildingIdx < numberOfOldBlockBuildings) {
return oldBlockBuildingColors[buildingIdx];
}
else {
return actualBlockBuildingColors[buildingIdx - numberOfOldBlockBuildings];
}
}

Transform GetActiveBuilding() {

Transform nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);
while (avatar.position.x + avatar.localScale.x * 0.5f > nextBuilding.position.x - nextBuilding.localScale.x * 0.5f) {
activeBuildingIndex++;
nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);
}
return GetBuildingForIdx(activeBuildingIndex);
}

ElementColor GetActiveBuildingColor() {

Transform nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);
while (avatar.position.x + avatar.localScale.x * 0.5f > nextBuilding.position.x - nextBuilding.localScale.x * 0.5f) {
activeBuildingIndex++;
nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);
}
return GetBuildingColorForIdx(activeBuildingIndex);
}

Transform GetNextBuilding() {

int nextBuildingIndex = activeBuildingIndex + 1;
Transform nextBuilding = GetBuildingForIdx(nextBuildingIndex);
while (avatar.position.x + avatar.localScale.x * 0.5f > nextBuilding.position.x - nextBuilding.localScale.x * 0.5f) {
nextBuildingIndex++;
nextBuilding = GetBuildingForIdx(nextBuildingIndex);
}
return nextBuilding;
}

bool IsAvatarInActiveBuildingColumn() {

Transform activeBuilding = GetActiveBuilding();
return (avatar.position.x - avatar.localScale.x * 0.5 < activeBuilding.position.x + activeBuilding.localScale.x * 0.5f);
}

float GetActiveBuildingGroundPosition() {

Transform activeBuilding = GetActiveBuilding();
return activeBuilding.position.y + activeBuilding.localScale.y * 0.5f;
}

float GetNextBuildingGroundPosition() {

Transform nextBuilding = GetNextBuilding();
return nextBuilding.position.y + nextBuilding.localScale.y * 0.5f;
}
}


Сообщение отредактировал Leon510 - Среда, 12 Марта 2014, 00:00
EchoITДата: Вторник, 11 Марта 2014, 15:07 | Сообщение # 2
старожил
Сейчас нет на сайте
Код
PlayerPrefs.SetInt("Name",5);

Позволяет задать переменную типа Integer с именем Name и значением 5. Вместо 5 подставляешь твою переменную рекорда, вместо Name удобное название.
Код
PlayerPrefs.GetInt("Name");

Позволяет получить обратно значение переменной типа Integer с именем Name.


Долгожданный анонсик: State of War

Сообщение отредактировал EchoIT - Вторник, 11 Марта 2014, 15:08
Leon510Дата: Вторник, 11 Марта 2014, 19:17 | Сообщение # 3
был не раз
Сейчас нет на сайте
Спс,а не могли бы вы помочь с этим куском кода? Надо как то пристроить сюда PlayerPrefs.SetInt.
// GUI data
int runDistance = Mathf.RoundToInt(avatar.position.x * 0.5f);
if (highscore < runDistance) {
highscore = runDistance;
}
if (prevRunDistance != runDistance) {
distanceLabel.text = System.Convert.ToString(runDistance);
prevRunDistance = runDistance;
}

if (prevHighscore != highscore) {
highscoreLabel.text = "Highscore:" + System.Convert.ToString(highscore);
prevHighscore = highscore;
}
}
EchoITДата: Вторник, 11 Марта 2014, 20:18 | Сообщение # 4
старожил
Сейчас нет на сайте
Код
int runDistance = Mathf.RoundToInt(avatar.position.x * 0.5f);
if (PlayerPrefs.GetInt("Highscore") < runDistance) {
PlayerPrefs.SetInt("Highscore", runDistance);
}
if (prevRunDistance != runDistance) {
distanceLabel.text = System.Convert.ToString(runDistance);
prevRunDistance = runDistance;
}

if (PlayerPrefs.GetInt("prevHighscore")  != PlayerPrefs.GetInt("Highscore") ) {
highscoreLabel.text = "Highscore:" + PlayerPrefs.GetInt("Highscore");
PlayerPrefs.SetInt("prevHighscore", PlayerPrefs.GetInt("Highscore"));
}
}

Так примерно.


Долгожданный анонсик: State of War
Leon510Дата: Вторник, 11 Марта 2014, 21:26 | Сообщение # 5
был не раз
Сейчас нет на сайте
Проверил на андроиде и на ипаде,не работает...
Этот скрипт для сохранения в реестр,а нужен в файл.
EchoITДата: Вторник, 11 Марта 2014, 21:49 | Сообщение # 6
старожил
Сейчас нет на сайте
Leon510, прекрасно работает всё, проверено.

Долгожданный анонсик: State of War
Leon510Дата: Вторник, 11 Марта 2014, 22:19 | Сообщение # 7
был не раз
Сейчас нет на сайте
EchoIT, А если я скину вам исходник с игрой,то вы можете сделать сохранение highsore?
Storm54Дата: Вторник, 11 Марта 2014, 22:25 | Сообщение # 8
постоянный участник
Сейчас нет на сайте
Нехорошо лепить все в один файл.
Leon510Дата: Вторник, 11 Марта 2014, 22:43 | Сообщение # 9
был не раз
Сейчас нет на сайте
Знаем...
Делали с готового бесплатного проекта.
Не мы весь код писали,только модефицировали.

Добавлено (11.03.2014, 22:43)
---------------------------------------------
Так сделаете сохранение?
А? Скриптеры добрые?

EchoITДата: Вторник, 11 Марта 2014, 22:43 | Сообщение # 10
старожил
Сейчас нет на сайте
Цитата
EchoIT, А если я скину вам исходник с игрой,то вы можете сделать сохранение highsore?

Я бы с радостью, да вот времени у меня мало. Я Вам уже показал примерный код, возможно в нём ошибка, возможно ещё где-то, но PlayerPrefs на мобильных платформах работает. Проверено на iOS и Android.


Долгожданный анонсик: State of War
Leon510Дата: Вторник, 11 Марта 2014, 22:45 | Сообщение # 11
был не раз
Сейчас нет на сайте
Понятно...
Storm54Дата: Вторник, 11 Марта 2014, 22:48 | Сообщение # 12
постоянный участник
Сейчас нет на сайте
Что именно не работает? Данные не сохраняются?

Сообщение отредактировал Storm54 - Вторник, 11 Марта 2014, 22:54
Leon510Дата: Вторник, 11 Марта 2014, 22:57 | Сообщение # 13
был не раз
Сейчас нет на сайте
Возможно и сохраняются,но не грузятся при следующем запуске игры
Storm54Дата: Вторник, 11 Марта 2014, 23:08 | Сообщение # 14
постоянный участник
Сейчас нет на сайте
Ясно. Попробуй так:

Код

void Start()
{
   highscore = PlayerPrefs.GetInt("Highscore");
}

void OnDestory()
{
   PlayerPrefs.SetInt("Highscore",highscore);
}


В теории все должно работать.


Сообщение отредактировал Storm54 - Вторник, 11 Марта 2014, 23:09
Leon510Дата: Вторник, 11 Марта 2014, 23:22 | Сообщение # 15
был не раз
Сейчас нет на сайте
Ну,в теории.
Поставите прямо в скрипт?
Код

using UnityEngine;  
using System.Collections.Generic;  

public class Game : MonoBehaviour {  

public Transform redBuilding;  
public Transform greenBuilding;  
public Transform avatar;  
public Rigidbody avatarRigidBody;  
public MeshRenderer avatarMeshRenderer;  
public TrailRenderer avatarTrailRenderer;  
public Rigidbody avatarDebris;  
public Material redMaterial;  
public Material greenMaterial;  
public Transform oldBackgroundBuildings;  
public Transform newBackgroundBuildings;  
public GUIText distanceLabel;  
public GUIText highscoreLabel;  
public GUITexture fullscreenOverlayTexture;  
public AudioClip[] jumpAudioClips;  
public AudioClip[] hitAudioClips;  
public AudioClip failAudioClip;  

// Private  
const int kMaxBlockBuildings = 50;  
const float kMinBlockWidth = 60;  
const float kStartAvatarSpeed = 8.0f;  
const float kAvatarSpeedIncCoef = 0.05f;  
const float kMaxAvatarSpeed = 11.0f;  
const float kGravity = 30.0f;  
const float kBounciness = 0.2f;  
const float kJumpEnergyDeplitionRate = 1.0f;  
const float kStartingJumpEnergy = 0.8f;  
const float kJumpEnergyEfficiencyCoef = 50.5f;  
const float kJumpRotationTime = 0.4f;  
const float kMinJumpImpulse = 4.0f;  
const float kCameraFriction = 0.7f;  
const float kHardestMinBuildingWidth = 4.0f;  
const float kHardestMaxBuildingWidth = 16.0f;  
const float kHardestMaxSpaceWidth = 3.5f;  
const float kFadeToMenuTime = 0.7f;  
const float kMinBuildingGround = -15.0f;  
const float kMaxBuildingGround = 5.0f;  
const float kHardestMaxBuildingGroundDifference = 1.2f;  

private Touch myTouch;  
private Touch myTouch2;  
public GUITexture jump;  
public GUITexture color;  
private bool touchFlag = false;  

// Local  
Transform transformRef;  

enum ElementColor {  
Red,  
Green,  
}  

Vector3 cameraVelocity;  

// Blocks  
Transform[] oldBlockBuildings;  
ElementColor[] oldBlockBuildingColors;  
int numberOfOldBlockBuildings;  
Transform[] actualBlockBuildings;  
ElementColor[] actualBlockBuildingColors;  
int numberOfActualBlockBuildings;  

int activeBuildingIndex;  
int activeBlockIndex;  

float actualBlockOffset;  
float actualBlockWidth;  
float actualBlockMinBuildingWidth;  
float actualBlockMaxBuildingWidth;  
float actualBlockMinSpaceWidth;  
float actualBlockMaxSpaceWidth;  
float actualBlockMaxBuildingGroundDifference;  
float lastBuildingGround;  

float jumpEnergy;  
bool readyForNextJump;  

// Avatar  
float avatarYVelocity;  
bool avatarHasContactWithGround;  
ElementColor avatarColor;  
float jumpRotationTimer;  
float avatarSpeed;  

// Menu  
float fadeToMenuTimer;  
int highscore;  
int prevRunDistance;  
int prevHighscore;  

// Game states  
enum GameState {  
Playing,  
FadeToMenu,  
Menu,  
};  

GameState gameState;  

// Use this for initialization  
void Start () {  

transformRef = transform;  

oldBlockBuildings = new Transform[kMaxBlockBuildings];  
actualBlockBuildings = new Transform[kMaxBlockBuildings];  
oldBlockBuildingColors = new ElementColor[kMaxBlockBuildings];  
actualBlockBuildingColors = new ElementColor[kMaxBlockBuildings];  

ResetGame();  
}  

//static int screenshotCount = 0;  

// Update is called once per frame  
void Update () {  

/*  
// take screenshot on up->down transition of F9 key  
if (Input.GetKeyDown("f9"))  
{  
string screenshotFilename;  
do  
{  
screenshotCount++;  
screenshotFilename = "screenshot" + screenshotCount + ".png";  

} while (System.IO.File.Exists(screenshotFilename));  

Application.CaptureScreenshot(screenshotFilename);  
}  
*/  

// New blocks  

if (avatar.position.x > actualBlockOffset + actualBlockBuildings[0].localScale.x)  
{  
CreateNewBlock();  
}  

if (gameState == GameState.Playing)  
{  

if (Input.touchCount > 0)  
{  
myTouch = Input.GetTouch(0);  

if ((jump.guiTexture.HitTest(myTouch.position)) && avatarHasContactWithGround && readyForNextJump && (myTouch.phase == TouchPhase.Began))  
{  
Jump();  
}  
if ((jump.guiTexture.HitTest(myTouch.position)) && (myTouch.phase == TouchPhase.Ended))  
{  
jumpEnergy = 0.0f;  
readyForNextJump = true;  
}  
if (Input.touchCount == 2)  
{  
myTouch2 = Input.GetTouch(1);  
if ((color.guiTexture.HitTest(myTouch2.position)) && (myTouch2.phase == TouchPhase.Began))  
{  
if (avatarColor == ElementColor.Green)  
{  
avatarMeshRenderer.material = redMaterial;  
avatarTrailRenderer.material = redMaterial;  
avatarColor = ElementColor.Red;  
}  
else  
{  
avatarMeshRenderer.material = greenMaterial;  
avatarTrailRenderer.material = greenMaterial;  
avatarColor = ElementColor.Green;  
}  
}  
}  
else if (Input.touchCount == 1)  
{  
myTouch2 = Input.GetTouch(0);  
if ((color.guiTexture.HitTest(myTouch2.position)) && (myTouch2.phase == TouchPhase.Began))  
{  
if (avatarColor == ElementColor.Green)  
{  
avatarMeshRenderer.material = redMaterial;  
avatarTrailRenderer.material = redMaterial;  
avatarColor = ElementColor.Red;  
}  
else  
{  
avatarMeshRenderer.material = greenMaterial;  
avatarTrailRenderer.material = greenMaterial;  
avatarColor = ElementColor.Green;  
}  
}  
}  
}  
}  

/*  
// Controlling game  
if (gameState == GameState.Playing) {  

// Jump  
if (Input.GetButtonDown("jump") && avatarHasContactWithGround && readyForNextJump) {  
Jump();  
}  
if (Input.GetButtonUp("jump")) {  
jumpEnergy = 0.0f;  
readyForNextJump = true;  
}  

// Switch  
if (Input.GetButtonDown("switch")) {  
if (avatarColor == ElementColor.Green) {  
avatarMeshRenderer.material = redMaterial;  
avatarTrailRenderer.material = redMaterial;  
avatarColor = ElementColor.Red;  
}  
else {  
avatarMeshRenderer.material = greenMaterial;  
avatarTrailRenderer.material = greenMaterial;  
avatarColor = ElementColor.Green;  
}  
}  
}  
*/  

else if (gameState == GameState.FadeToMenu) {  

fullscreenOverlayTexture.color = new Color(0.5f, 0.5f, 0.5f, 0.5f * fadeToMenuTimer / kFadeToMenuTime);  

fadeToMenuTimer += Time.deltaTime;  
if (fadeToMenuTimer >= kFadeToMenuTime) {  
gameState = GameState.Menu;  
fullscreenOverlayTexture.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);  
avatarRigidBody.isKinematic = true;  
}  
}  
else if (gameState == GameState.Menu) {  
if (Input.anyKeyDown) {  
ResetGame();  
}  
}  

// GUI data  
int runDistance = Mathf.RoundToInt(avatar.position.x * 0.5f);  
if (highscore < runDistance) {  
highscore = runDistance;  
}  
if (prevRunDistance != runDistance) {  
distanceLabel.text = System.Convert.ToString(runDistance);  
prevRunDistance = runDistance;  
}  

if (prevHighscore != highscore) {  
highscoreLabel.text = "Highscore:" + System.Convert.ToString(highscore);  
prevHighscore = highscore;  
}  
}  

void FixedUpdate()  
{  

// Camera pos  
Vector3 cameraPosition = transformRef.position;  
Vector3 designatedPosition = new Vector3(avatar.position.x + 3.5f, avatar.position.y + 0.2f, cameraPosition.z);  
cameraVelocity += (designatedPosition - cameraPosition) * Time.deltaTime * 10.0f;  
cameraVelocity *= kCameraFriction;  
cameraPosition += cameraVelocity * Time.deltaTime * 10.0f;  
cameraPosition.x = avatar.position.x + 3.4f;  
transformRef.position = cameraPosition;  

// Avatar physics  
if (gameState == GameState.Playing)  
{  

// Avatar speed  
if (avatarSpeed < kMaxAvatarSpeed)  
{  
avatarSpeed += kAvatarSpeedIncCoef * Time.deltaTime;  
if (avatarSpeed > kMaxAvatarSpeed)  
{  
avatarSpeed = kMaxAvatarSpeed;  
}  
}  

// Jumping  

if (jump.guiTexture.HitTest(myTouch.position) && jumpEnergy > 0 && (myTouch.phase == TouchPhase.Stationary))  
{  
avatarYVelocity += jumpEnergy * kJumpEnergyEfficiencyCoef * Time.deltaTime;  
jumpEnergy -= kJumpEnergyDeplitionRate * Time.deltaTime;  
}  

bool potentialFailCollision = (!IsAvatarInActiveBuildingColumn() && (avatar.position.y - avatar.localScale.y * 0.5f < GetNextBuildingGroundPosition()));  

avatarYVelocity -= kGravity * Time.deltaTime;  

Vector3 position = avatar.position;  
Vector3 prevPosition = position;  
position.x += Time.deltaTime * avatarSpeed;  
position.y += Time.deltaTime * avatarYVelocity;  
avatar.position = position;  

// Rotation  
if (!avatarHasContactWithGround && jumpRotationTimer < kJumpRotationTime)  
{  
float t = Mathf.Sin(jumpRotationTimer / kJumpRotationTime * Mathf.PI);  
Quaternion rotation = avatar.rotation;  
rotation.z = -t * Mathf.PI * 0.15f;  
avatar.rotation = rotation;  
jumpRotationTimer += Time.deltaTime;  
}  
else  
{  
Quaternion rotation = avatar.rotation;  
rotation.z = 0.0f;  
avatar.rotation = rotation;  
}  

float groundPosition = GetActiveBuildingGroundPosition();  
if (IsAvatarInActiveBuildingColumn())  
{  

if (position.y - avatar.localScale.y * 0.5f < groundPosition)  
{  

if (!avatarHasContactWithGround)  
{  
AudioSource.PlayClipAtPoint(hitAudioClips[Random.Range(0, hitAudioClips.Length)], avatar.position);  
}  

avatarHasContactWithGround = true;  
jumpRotationTimer = kJumpRotationTime;  

// Fail  
if (potentialFailCollision || GetActiveBuildingColor() != avatarColor)  
{  
FadeToMenu();  
avatar.position = prevPosition;  
avatarRigidBody.isKinematic = false;  
avatarRigidBody.AddForce(new Vector3(avatarSpeed * 40.0f, avatarYVelocity * 20.0f, 0.0f));  
AudioSource.PlayClipAtPoint(failAudioClip, avatar.position);  
CreateFailDebris();  
}  
// Bounce  
else  
{  
jumpEnergy = 0;  
if (avatarYVelocity < 0)  
{  
avatarYVelocity = -avatarYVelocity * kBounciness;  
}  
position.y = groundPosition + avatar.localScale.y * 0.5f;  
avatar.position = position;  
}  

if (jump.guiTexture.HitTest(myTouch.position) && readyForNextJump && (myTouch.phase == TouchPhase.Stationary))  
{  
Jump();  
}  
}  
}  
else  
{  
avatarHasContactWithGround = false;  
}  
}  
}  

void FadeToMenu() {  

gameState = GameState.FadeToMenu;  
fullscreenOverlayTexture.enabled = true;  
fullscreenOverlayTexture.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);  
fadeToMenuTimer = 0;  
}  

void ResetGame() {  

fullscreenOverlayTexture.enabled = false;  

actualBlockOffset = 0;  
actualBlockWidth = 0;  
activeBuildingIndex = 0;  
activeBlockIndex = 0;  

actualBlockMinBuildingWidth = 18;  
actualBlockMaxBuildingWidth = 20;  
actualBlockMinSpaceWidth = 1.4f;  
actualBlockMaxSpaceWidth = 1.6f;  
actualBlockMaxBuildingGroundDifference = 0.5f;  
lastBuildingGround = 0.0f;  

CreateNewBlock();  
CreateNewBlock();  

avatarColor = oldBlockBuildingColors[0];  
if (avatarColor == ElementColor.Green) {  
avatarMeshRenderer.material = greenMaterial;  
avatarTrailRenderer.material = greenMaterial;  
}  
else {  
avatarMeshRenderer.material = redMaterial;  
avatarTrailRenderer.material = redMaterial;  
}  

avatarSpeed = kStartAvatarSpeed;  
jumpEnergy = kStartingJumpEnergy;  
readyForNextJump = true;  

avatarRigidBody.isKinematic = true;  
avatar.transform.rotation = Quaternion.identity;  
avatar.position = new Vector3(1.0f, 1.5f, 0.0f);  

transform.position = new Vector3(8.0f, 1.2f, -30.0f);  

gameState = GameState.Playing;  
}  

void Jump() {  
jumpEnergy = kStartingJumpEnergy;  
avatarHasContactWithGround = false;  
jumpRotationTimer = 0;  
avatarYVelocity += kMinJumpImpulse;  
readyForNextJump = false;  
AudioSource.PlayClipAtPoint(jumpAudioClips[Random.Range(0, jumpAudioClips.Length)], avatar.position);  
}  

void CreateNewBlock() {  

// Switch BG  
Transform bgBuildings = oldBackgroundBuildings;  
oldBackgroundBuildings = newBackgroundBuildings;  
newBackgroundBuildings = bgBuildings;  

// Update active building index  
if (activeBuildingIndex >= numberOfOldBlockBuildings) {  
activeBuildingIndex -= numberOfOldBlockBuildings;  
}  
// Delete objects in old block  
for (int i = 0; i < kMaxBlockBuildings; i++) {  
if (oldBlockBuildings[i]) {  
Destroy(oldBlockBuildings[i].gameObject);  
oldBlockBuildings[i] = null;  
}  
}  

System.Array.Copy(actualBlockBuildings, oldBlockBuildings, numberOfActualBlockBuildings);  
System.Array.Copy(actualBlockBuildingColors, oldBlockBuildingColors, numberOfActualBlockBuildings);  
numberOfOldBlockBuildings = numberOfActualBlockBuildings;  
numberOfActualBlockBuildings = 0;  

// New params  
if (actualBlockMinBuildingWidth > kHardestMinBuildingWidth) {  
actualBlockMinBuildingWidth -= 2.0f;  
if (actualBlockMinBuildingWidth < kHardestMinBuildingWidth) {  
actualBlockMinBuildingWidth = kHardestMinBuildingWidth;  
}  
}  

if (actualBlockMaxBuildingWidth > kHardestMaxBuildingWidth) {  
actualBlockMaxBuildingWidth -= 2.0f;  
if (actualBlockMaxBuildingWidth < kHardestMaxBuildingWidth) {  
actualBlockMaxBuildingWidth = kHardestMaxBuildingWidth;  
}  
}  

if (actualBlockMaxSpaceWidth < kHardestMaxSpaceWidth) {  
actualBlockMaxSpaceWidth += 0.5f;  
if (actualBlockMaxSpaceWidth > kHardestMaxSpaceWidth) {  
actualBlockMaxSpaceWidth = kHardestMaxSpaceWidth;  
}  
}  

if (actualBlockMaxBuildingGroundDifference < kHardestMaxBuildingGroundDifference) {  
actualBlockMaxBuildingGroundDifference += 0.1f;  
if (actualBlockMaxBuildingGroundDifference > kHardestMaxBuildingGroundDifference) {  
actualBlockMaxBuildingGroundDifference = kHardestMaxBuildingGroundDifference;  
}  
}  

actualBlockOffset += actualBlockWidth;  
float offset = actualBlockOffset;  
actualBlockWidth = 0;  

bool creatingSpace = true;  
while (actualBlockWidth < kMinBlockWidth || !creatingSpace) {  

// Space  
if (creatingSpace) {  
float spaceWidth = Random.Range(actualBlockMinSpaceWidth, actualBlockMaxSpaceWidth);  
offset += spaceWidth;  
actualBlockWidth += spaceWidth;  
}  
// Building  
else {  
if (numberOfActualBlockBuildings == kMaxBlockBuildings - 1) {  
break;  
}  
else {  
float buildingWidth = Random.Range(actualBlockMinBuildingWidth, actualBlockMaxBuildingWidth);  

if (activeBlockIndex % 4 == 0) {  
lastBuildingGround += actualBlockMaxBuildingGroundDifference * 0.3f;  
buildingWidth = actualBlockMinBuildingWidth * 1.2f;  
}  
else if ((activeBlockIndex - 2) % 4 == 0 && activeBlockIndex > 4) {  
lastBuildingGround -= actualBlockMaxBuildingGroundDifference * 0.2f;  
buildingWidth = actualBlockMinBuildingWidth * 1.7f;  
}  
else {  
lastBuildingGround += Random.Range(-actualBlockMaxBuildingGroundDifference, actualBlockMaxBuildingGroundDifference);  
}  

if (lastBuildingGround < kMinBuildingGround) {  
lastBuildingGround = kMinBuildingGround;  
}  
else if (lastBuildingGround > kMaxBuildingGround) {  
lastBuildingGround = kMaxBuildingGround;  
}  

ElementColor color = (Random.Range(0, 2) == 0) ? ElementColor.Red : ElementColor.Green;  
Transform building = (color == ElementColor.Red ? redBuilding : greenBuilding);  
Transform newBuilding = (Transform)Instantiate(building, new Vector3((offset + buildingWidth * 0.5f), lastBuildingGround - 25.0f, 0.0f), Quaternion.identity);  
newBuilding.transform.localScale = new Vector3(buildingWidth, 50.0f, 0.2f);  
actualBlockBuildings[numberOfActualBlockBuildings] = newBuilding;  
actualBlockBuildingColors[numberOfActualBlockBuildings] = color;  
numberOfActualBlockBuildings++;  
offset += buildingWidth;  
actualBlockWidth += buildingWidth;  
}  
}  

creatingSpace = !creatingSpace;  
}  

Vector3 bgBuildingsPos = newBackgroundBuildings.position;  
bgBuildingsPos.x = actualBlockOffset + actualBlockWidth * 0.5f;  
newBackgroundBuildings.position = bgBuildingsPos;  

Vector3 bgBuildingsScale = newBackgroundBuildings.localScale;  
bgBuildingsScale.x = actualBlockWidth;  
newBackgroundBuildings.localScale = bgBuildingsScale;  

activeBlockIndex++;  
}  

void CreateFailDebris() {  
for (int i = 0; i < 30; i++) {  
Vector3 pos = Random.onUnitSphere * 0.2f + avatar.position;  
Rigidbody debris = (Rigidbody)Instantiate(avatarDebris, pos, Quaternion.identity);  
debris.AddForce(new Vector3(avatarSpeed * 40.0f, avatarYVelocity * 20.0f, 0.0f));  
MeshRenderer debrisMeshRenderer = debris.GetComponent<MeshRenderer>();  
if (avatarColor == ElementColor.Green) {  
debrisMeshRenderer.material = greenMaterial;  
}  
else {  
debrisMeshRenderer.material = redMaterial;  
}  
}  
}  

Transform GetBuildingForIdx(int buildingIdx) {  

if (buildingIdx < numberOfOldBlockBuildings) {  
return oldBlockBuildings[buildingIdx];  
}  
else {  
return actualBlockBuildings[buildingIdx - numberOfOldBlockBuildings];  
}  
}  

ElementColor GetBuildingColorForIdx(int buildingIdx) {  
if (buildingIdx < numberOfOldBlockBuildings) {  
return oldBlockBuildingColors[buildingIdx];  
}  
else {  
return actualBlockBuildingColors[buildingIdx - numberOfOldBlockBuildings];  
}  
}  

Transform GetActiveBuilding() {  

Transform nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);  
while (avatar.position.x + avatar.localScale.x * 0.5f > nextBuilding.position.x - nextBuilding.localScale.x * 0.5f) {  
activeBuildingIndex++;  
nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);  
}  
return GetBuildingForIdx(activeBuildingIndex);  
}  

ElementColor GetActiveBuildingColor() {  

Transform nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);  
while (avatar.position.x + avatar.localScale.x * 0.5f > nextBuilding.position.x - nextBuilding.localScale.x * 0.5f) {  
activeBuildingIndex++;  
nextBuilding = GetBuildingForIdx(activeBuildingIndex + 1);  
}  
return GetBuildingColorForIdx(activeBuildingIndex);  
}  

Transform GetNextBuilding() {  

int nextBuildingIndex = activeBuildingIndex + 1;  
Transform nextBuilding = GetBuildingForIdx(nextBuildingIndex);  
while (avatar.position.x + avatar.localScale.x * 0.5f > nextBuilding.position.x - nextBuilding.localScale.x * 0.5f) {  
nextBuildingIndex++;  
nextBuilding = GetBuildingForIdx(nextBuildingIndex);  
}  
return nextBuilding;  
}  

bool IsAvatarInActiveBuildingColumn() {  

Transform activeBuilding = GetActiveBuilding();  
return (avatar.position.x - avatar.localScale.x * 0.5 < activeBuilding.position.x + activeBuilding.localScale.x * 0.5f);  
}  

float GetActiveBuildingGroundPosition() {  

Transform activeBuilding = GetActiveBuilding();  
return activeBuilding.position.y + activeBuilding.localScale.y * 0.5f;  
}  

float GetNextBuildingGroundPosition() {  

Transform nextBuilding = GetNextBuilding();  
return nextBuilding.position.y + nextBuilding.localScale.y * 0.5f;  
}  
}
EchoITДата: Вторник, 11 Марта 2014, 23:26 | Сообщение # 16
старожил
Сейчас нет на сайте
Leon510, я бы советовал сначала выучить основы C# и Unity3d. wink

Долгожданный анонсик: State of War
Storm54Дата: Вторник, 11 Марта 2014, 23:31 | Сообщение # 17
постоянный участник
Сейчас нет на сайте
Поставь перед последней фигурной скобкой.
Leon510Дата: Вторник, 11 Марта 2014, 23:32 | Сообщение # 18
был не раз
Сейчас нет на сайте
Я вообще то спец по многим движкам...Стаж в геймдеве уже 4 года.
А основы C scharp я знаю....Я уже несколько скриптов писал для проектов. wink
Storm54Дата: Вторник, 11 Марта 2014, 23:36 | Сообщение # 19
постоянный участник
Сейчас нет на сайте
Цитата
Я вообще то спец по многим движкам...Стаж в геймдеве уже 4 года.
А основы C scharp я знаю....Я уже несколько скриптов писал для проектов.

Как сказал Станиславский: "Не верю!"

Если по теме: Не заметил, что в скрипте уже есть метод Start(), так что
Код
highscore = PlayerPrefs.GetInt("Highscore");

поставь туда.


Сообщение отредактировал Storm54 - Вторник, 11 Марта 2014, 23:38
Leon510Дата: Вторник, 11 Марта 2014, 23:41 | Сообщение # 20
был не раз
Сейчас нет на сайте
Это потому что скрипт привязан к main camera!! wink
И к сведенью я в скриптинге почти новичек,но все же многое умею.
А насчет геймдева уже реально четвертый год идет. biggrin
Форум игроделов » Движки для разработки игр и сложные системы разработки » Unity » Скриптирование (С#,java итд)
  • Страница 1 из 2
  • 1
  • 2
  • »
Поиск:

Все права сохранены. GcUp.ru © 2008-2022 Рейтинг