Chaîne YouTube de tutos français

Tous les tutoriaux unity, de la communauté ou d'ailleurs.
Defcon44
Messages : 147
Inscription : 13 Avr 2014 14:06

Re: Chaîne YouTube de tutos français

Message par Defcon44 » 19 Juin 2014 13:59

Merci pour tes vidéos!
Elles m'aident énormément ^^

Mais j'ai un soucis avec le script "CarUserControl.cs" (vidéo pour conduire une voiture).

Le Code :

Code : Tout sélectionner

using UnityEngine;

[RequireComponent(typeof CarController)]
public class CarUserControl : MonoBehaviour{

    private CarController car;  // the car controller we want to use
    

    void Awake ()
    {
        // get the car controller
        car = GetComponent<CarController>();
    }


    void FixedUpdate()
    {
		if(Global.isInCar && Global.car == transform){
			float h = CrossPlatformInput.GetAxis("Horizontal");
			float v = CrossPlatformInput.GetAxis("Vertical");
	        car.Move(h,v);
		}
    }

	void OnTriggerStay(Collider obj){

		if(obj.tag == "Player" && !Global.isInCar){
			Global.ShowText("Appuyez sur E prendre le véhicule");

			if(Input.GetKeyDown(Global.actionKey)){
				Global.car = transform;
				Global.SwitchPlayer();
			}
		}

	}

	void OnTriggerExit(Collider obj){
		if(obj.tag == "Player"){
			Global.ShowText("");
		}
	}


} //end of class
J'ai modifié le nom de la caméra et certaine autre petite chose car j'importe le script dans mon projet :)

Donc voilà le problème, dans la console il me dit que j'ai une erreur à la ligne 45 donc la toute dernière celle avec le commentaire ... mais je ne comprend pas.

Un idée SVP ?

Avatar de l’utilisateur
GTSAReeper
Messages : 230
Inscription : 21 Juil 2013 02:12
Localisation : Creuse - Limousin

Re: Chaîne YouTube de tutos français

Message par GTSAReeper » 20 Juin 2014 19:04

Bonsoir
Remplace sa :

Code : Tout sélectionner

[RequireComponent(typeof CarController)]
par sa :

Code : Tout sélectionner

[RequireComponent(typeof (CarController))]
[center]Image[/center]

Defcon44
Messages : 147
Inscription : 13 Avr 2014 14:06

Re: Chaîne YouTube de tutos français

Message par Defcon44 » 28 Juin 2014 20:24

Merci mais j'avais trouver ^^

Mon nouveau problème viens du global.cs

Code :

Code : Tout sélectionner

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Global : MonoBehaviour {

	#region Attributes
	public static Transform player;
	public static Transform car;

	public static Camera maincamera;
	public static bool isInCar = false;

	public static GUIText mainText;

	public static KeyCode actionKey = KeyCode.F;

	public static float timeToWait = 2.0F;
	public static float lastChange = 0;
	#endregion
	
	#region Unity methods
	/// <summary>
	/// Start this instance.
	/// </summary>
	void Awake () {
		player = GameObject.FindGameObjectWithTag("Player").transform;
		car = GameObject.FindGameObjectWithTag("Car").transform;

		maincamera = GameObject.Find ("Main Camera").GetComponent<Camera>();

		mainText = GameObject.Find ("MainText").guiText;
	}
	
	/// <summary>
	/// Update this instance.
	/// </summary>
	void Update () {
	
		if(Time.fixedTime - lastChange >= timeToWait && isInCar && !player.gameObject.activeSelf && Input.GetKeyDown(actionKey)){
			SwitchPlayer();
		}

	}
	#endregion
	
	#region Other methods
	public static void SwitchPlayer(){
		if(maincamera != null){
			if(isInCar){
				player.gameObject.SetActive(true);

				player.position = car.position + (Vector3.back * 2);

				maincamera.SetTarget(player);
				isInCar = false;
			} else {
				ShowText("");
				player.gameObject.SetActive(false);
				maincamera.SetTarget(car);
				isInCar = true;
			}

			lastChange = Time.fixedTime;
		}
	}

	public static void ShowText(string str){
		if(mainText != null) mainText.text = str;
	}
	#endregion

	
} // End class
Erreur dans la console :

Assets/Global.cs(63,44): error CS1061: Type `UnityEngine.Camera' does not contain a definition for `SetTarget' and no extension method `SetTarget' of type `UnityEngine.Camera' could be found (are you missing a using directive or an assembly reference?)
Assets/Global.cs(68,44): error CS1061: Type `UnityEngine.Camera' does not contain a definition for `SetTarget' and no extension method `SetTarget' of type `UnityEngine.Camera' could be found (are you missing a using directive or an assembly reference?)

Une idée svp ?

Avatar de l’utilisateur
Max
Messages : 8772
Inscription : 30 Juil 2011 13:57
Contact :

Re: Chaîne YouTube de tutos français

Message par Max » 29 Juin 2014 10:41

C'est le même post et exactement la même question qu'ici non ? viewtopic.php?f=7&t=8389#p64090

EDIT: Dans le tuto original, la définition originale n'est pas public static Camera maincamera;, mais public static FreeLookCam flc; (qui comprend bien donc une fonction SetTarget).
Remplacer simplement FreeLookCam par Camera ne permettra pas d'en employer les methods, un peu comme par magie.
Si tu veux reprendre le code à ton compte, il faut aussi en comprendre un peu la logique et les éléments qui le compose pour l'adapter à tes besoins ;)
Image
Pas d'aide par MP, le forum est là pour ça.
En cas de doute sur les bonnes pratiques à adopter sur le forum, consulter la Charte et sa FAQ

Répondre

Revenir vers « Tutoriaux »