Accueil Forums J’ai besoin d’aide Unity3D Bessoin d'aide comment ecraser des ennemi avec un vehicule ! Répondre à : Bessoin d'aide comment ecraser des ennemi avec un vehicule !

#1532

Veraliot_
Participant

Alors j’ai un peux de mal a faire mon script malgré ton aide j’ai débuter par ça mais il as une erreur (Gravité Code Description Projet Fichier Ligne État de la suppression
Erreur CS0029 Impossible de convertir implicitement le type float en bool) qui me tracasse sinon tu ne pourrais pas me montrer comment faire un script assez propre et qui marche?? encore désoler de te derranger et merci de prendre ton temps pour corriger mes erreur!
je te passe mes différents scripts et celui qui as l’erreur!

<pre class=”lang:c# decode:true ” title=”Script Test!” >public class KillPlayer : MonoBehaviour {
public float DansLaZone;

// Use this for initialization
void Start()
{

}
void OnCollisionEnter(Collision Other)
{
if (Other.gameObject.GetComponent<CarController>().Speed)
{

}
}
}

<pre class=”lang:c# decode:true ” title=”Script qui gére la vitesse CarController” >using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CarController : MonoBehaviour
{

public Text TxtSpeed;
public WheelCollider front_left;
public WheelCollider front_right;
public WheelCollider back_left;
public WheelCollider back_right;
public float Torque;
public float Speed;
public float MaxSpeed = 301f;
public int Brake = 10000;
public int Slip = 10000;
public bool Drift = false;
public float CoefAcceleration = 10f;
public float WheelAngleMax = 10f;
public bool Freinage = false;
public GameObject BackLight;
public float DaMax = 40f;
public Transform FL;
public Transform FR;
public Transform BL;
public Transform BR;
public GameObject LightOfReverseGear;
public GameObject Carlight;
public bool carLightToogle;
public GameObject TyreTrack;
public GameObject Tyretrack;
public Vector3 centerOfMass;
public bool Is4x4;
public AudioSource CarAcceleration;
public AudioSource CarIdle;
public AudioSource RearSound;

void start()
{
//reglage du centerOfMass
GetComponent<Rigidbody>().centerOfMass = centerOfMass;
}

void Update()
{
//Son du vehicule
float Val_Volume = Speed / MaxSpeed + 1f;
CarAcceleration.pitch = Mathf.Clamp(Val_Volume, 1f, 3f);
CarIdle.pitch = Mathf.Clamp(Val_Volume, 1f, 3f);

//Afichage de la vitesse
Speed = GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
TxtSpeed.text = “MPH: ” + (int)Speed;

//Acceleration
if(Input.GetAxis(“Vertical”) >= 0 && Speed < MaxSpeed)
{
if (!Freinage)
{
front_left.brakeTorque = 0;
front_right.brakeTorque = 0;
back_left.brakeTorque = 0;
back_right.brakeTorque = 0;
back_left.motorTorque = Input.GetAxis(“Vertical”) * Torque * CoefAcceleration * Time.deltaTime;
back_right.motorTorque = Input.GetAxis(“Vertical”) * Torque * CoefAcceleration * Time.deltaTime;
}
if (Is4x4)
{
front_left.motorTorque = Input.GetAxis(“Vertical”) * Torque * CoefAcceleration * Time.deltaTime;
front_right.motorTorque = Input.GetAxis(“Vertical”) * Torque * CoefAcceleration * Time.deltaTime;
}

}

//Décéleration
if (Input.GetAxis(“Vertical”) < 0 && !Freinage || Speed > MaxSpeed)
{
if (GetComponent<Rigidbody>().velocity.y > 1)
{
back_left.motorTorque = 30000;
back_right.motorTorque = 30000;
}
else
{
back_left.brakeTorque = 80000000;
back_right.brakeTorque = 8000000;
}
if (Is4x4)
{
front_left.motorTorque = 30000;
front_right.motorTorque = 30000;
}
else
{
front_left.brakeTorque = 8000000;
front_right.brakeTorque = 8000000;
}
}

//Direction du Vehicule
float Da = (((WheelAngleMax – DaMax) / MaxSpeed) * Speed) + DaMax;

front_left.steerAngle = Input.GetAxis(“Horizontal”) * Da;
front_right.steerAngle = Input.GetAxis(“Horizontal”) * Da;

//Rotation des roues
FL.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
FR.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
BL.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
BR.Rotate(front_left.rpm / 60 * 360 * Time.deltaTime, 0, 0);
//SteerAngle Mesh(objet) roue
FL.localEulerAngles = new Vector3(FL.localEulerAngles.x, front_left.steerAngle – FL.localRotation.z);
FR.localEulerAngles = new Vector3(FR.localEulerAngles.x, front_right.steerAngle – FR.localRotation.z);

//feux du vehicule
if (Input.GetKeyDown(KeyCode.Keypad1))
{
carLightToogle = !carLightToogle;
}
if (carLightToogle)
{
Carlight.SetActive(true);
}
else
{
Carlight.SetActive(false);
}
//Freinage
if (Input.GetAxis(“Frein”) >= 1)
{
Freinage = true;
BackLight.SetActive(true);
back_left.brakeTorque = Mathf.Infinity;
back_right.brakeTorque = Mathf.Infinity;
front_left.brakeTorque = Mathf.Infinity;
front_right.brakeTorque = Mathf.Infinity;
back_left.motorTorque = 0;
back_right.motorTorque = 0;
}
else
{
Freinage = false;
BackLight.SetActive(false);
}
//Drift
if (Input.GetAxis(“HandBrake”) >= 1)
{
Drift= true;
WheelFrictionCurve myWfc;
myWfc = back_left.sidewaysFriction;
myWfc.extremumSlip = Slip;
back_left.sidewaysFriction = myWfc;
TyreTrack.SetActive(true);
Tyretrack.SetActive(true);
myWfc = back_right.sidewaysFriction;
myWfc.extremumSlip = Slip;
back_right.sidewaysFriction = myWfc;
}
else
{
Drift = false;
WheelFrictionCurve myWfc;
myWfc = back_left.sidewaysFriction;
myWfc.extremumSlip = 0f;
back_left.sidewaysFriction = myWfc;
TyreTrack.SetActive(false);
Tyretrack.SetActive(false);
myWfc = back_right.sidewaysFriction;
myWfc.extremumSlip = 0f;
back_right.sidewaysFriction = myWfc;
}
//Marche Arriére
if (Input.GetAxis(“Reverse”) >= 1)
{
LightOfReverseGear.SetActive(true);
front_left.brakeTorque = 0;
front_right.brakeTorque = 0;
back_left.brakeTorque = 0;
back_right.brakeTorque = 0;
back_left.motorTorque = Input.GetAxis(“Vertical”) * Torque * CoefAcceleration * Time.deltaTime;
back_right.motorTorque = Input.GetAxis(“Vertical”) * Torque * CoefAcceleration * Time.deltaTime;
RearSound.enabled = true;
}
else
{
LightOfReverseGear.SetActive(false);
RearSound.enabled = false;
}

}

}

<pre class=”lang:c# decode:true ” title=”Et enfin celui qui gere la mort” >using UnityEngine;
using UnityStandardAssets.ImageEffects;

public class CharacterStats : MonoBehaviour {

private CharacterController characterController { get { return GetComponent<CharacterController>(); } set { characterController = value; } }
private RagdollManager RagMan { get { return GetComponentInChildren<RagdollManager>(); } set { RagMan = value; } }
private Animator anim { get { return GetComponent<Animator>(); } set { anim = value; } }
public Rigidbody Hips;
public Rigidbody LeftUpLeg;
public Rigidbody RightUpLeg;
public Rigidbody LeftLeg;
public Rigidbody RightLeg;
public Rigidbody Spine1;
public Rigidbody LeftArm;
public Rigidbody RightArm;
public Rigidbody LeftForeArm;
public Rigidbody RightForeArm;
public Rigidbody Head;
public Camera DeathCam;
public bool IsAi;

[Range(0, 100)] public float health = 100;
public int faction;

public MonoBehaviour[] ScriptsToDisable;

// Update is called once per frame
void Update()
{
health = Mathf.Clamp(health, 0, 100);
}
public void Damage(float damage)
{
health -= damage;

if (health <= 0)
{
Die ();
}
}

public void Die ()
{
//ragdoll
Hips.isKinematic = false;
LeftUpLeg.isKinematic = false;
RightUpLeg.isKinematic = false;
LeftLeg.isKinematic = false;
RightLeg.isKinematic = false;
Spine1.isKinematic = false;
LeftArm.isKinematic = false;
RightArm.isKinematic = false;
LeftForeArm.isKinematic = false;
RightForeArm.isKinematic = false;
Head.isKinematic = false;
characterController.enabled = false;
anim.enabled = false;
anim.applyRootMotion = false;
DeathCam.GetComponent<Grayscale>().enabled = true;
Time.timeScale = 0.3f;
if (IsAi)
{
DeathCam.GetComponent<Grayscale>().enabled = false;
Time.timeScale = 1f;
}

if (ScriptsToDisable.Length == 0)
{
Debug.Log(“Tous les scripts restent en marche sur le personnage en question mais il est mort”);
return;
}
foreach (MonoBehaviour script in ScriptsToDisable)
{
script.enabled = false;
}
if (RagMan != null)
RagMan.Ragdoll();
}
}