0
\$\begingroup\$

I'm new here and I have a question. (Help me Google Translate). At first I make camera from this video.

First video

First script (CameraController)

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {

    public PlayerController player;

    [Header ("Привязка камеры")]
    public bool isFollowing;
    public float xOffset;
    public float yOffset;

    // Use this for initialization
    void Start () {
        player = FindObjectOfType<PlayerController>();

        isFollowing = true;
    }

    // Update is called once per frame
    void Update () {
        if (isFollowing)
            transform.position = new Vector3 (player.transform.position.x+xOffset, player.transform.position.y+yOffset, transform.position.z);
    }
}

Second video

Second script (CameraFollow)

using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {

    private Vector2 velocity;

    public float smoothTimeY;
    public float smoothTimeX;

    //public GameObject player;
    public PlayerController player;

    public bool bounds;

    public Vector3 minCameraPos;
    public Vector3 maxCameraPos;

    // Use this for initialization
    void Start () {

        //player = GameObject.FindGameObjectsWithTag ("Player");
        player = FindObjectOfType<PlayerController>();

    }

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

        float posX = Mathf.SmoothDamp (transform.position.x, player.transform.position.x, ref velocity.x, smoothTimeX);
        float posY = Mathf.SmoothDamp (transform.position.y, player.transform.position.y, ref velocity.x, smoothTimeY);

        transform.position = new Vector3 (posX, posY, transform.position.z);

        if (bounds)
        {
            transform.position = new Vector3(Mathf.Clamp(transform.position.x, minCameraPos.x, maxCameraPos.x),
                                             Mathf.Clamp(transform.position.y, minCameraPos.y, maxCameraPos.y),
                                             Mathf.Clamp(transform.position.z, minCameraPos.z, maxCameraPos.z));
        }
    }
}

I want to do like in second video, but when my hero died. He becomes invisible. How to fix it?

MyProject

Thanks in advance!

UPDATE:

Script(LevelManeger)

using UnityEngine;
using System.Collections;

public class LevelManeger : MonoBehaviour {

    public GameObject currentCheckpoint;

    private PlayerController player;

    public HealthManager healthManager;

    [Space(10)]
    [Header ("Штраф")]
    public int pointPenaltyOnDeath;


    // Use this for initialization
    void Start () {

        player = FindObjectOfType<PlayerController> ();

        healthManager = FindObjectOfType<HealthManager> ();
    }

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

    }

    public void RespawnPlayer()
    {
        ScoreManager.AddPoints (-pointPenaltyOnDeath);
        Debug.Log ("Player Respawn");
        player.transform.position = currentCheckpoint.transform.position;
        healthManager.FullHealth ();
    }
}
\$\endgroup\$
  • \$\begingroup\$ What are you in your playerscript when the player dies? \$\endgroup\$ – Mattias Dec 19 '15 at 8:08
  • \$\begingroup\$ @Mattias Update.Also you can check my scripts in my project.Check link. \$\endgroup\$ – Artik Slayer Dec 19 '15 at 16:27
  • \$\begingroup\$ Any error you are getting? \$\endgroup\$ – Hamza Hasan Dec 19 '15 at 19:24
  • \$\begingroup\$ @HamzaHasan no/ \$\endgroup\$ – Artik Slayer Dec 19 '15 at 20:08
  • \$\begingroup\$ I tried to run your project, but as usual all references are removed and some objects are even not in scene and your script is trying to access it \$\endgroup\$ – Hamza Hasan Dec 19 '15 at 20:10
1
\$\begingroup\$

Change the Z position of Checkpoint gameObject from -10 to 0.

This is because your MainCamera has clipping planes with 0.3 to 1000 and you are spawning your Hero even behind the Near Plane (Clipping plane).

Clipping Planes are the attributes of Camera to let Camera know that From where To where Camera has to render all stuff.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.