Input des boutons du joueurs

This commit is contained in:
max89max 2015-11-08 16:08:55 +01:00
parent c5a8b5d9fa
commit 032ce91118
8 changed files with 521 additions and 416 deletions

View File

@ -85,139 +85,48 @@ NavMeshSettings:
cellSize: .166666672
manualCellSize: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &504302917
GameObject:
--- !u!1001 &273764419
Prefab:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 504302921}
- 33: {fileID: 504302920}
- 65: {fileID: 504302919}
- 23: {fileID: 504302918}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &504302918
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 504302917}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_SubsetIndices:
m_StaticBatchRoot: {fileID: 0}
m_UseLightProbes: 1
m_ReflectionProbeUsage: 1
m_ProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_ImportantGI: 0
m_AutoUVMaxDistance: .5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!65 &504302919
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 504302917}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &504302920
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 504302917}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &504302921
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 504302917}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -.860000014, z: -.416000009}
m_LocalScale: {x: 4.98590565, y: .245846689, z: 4.98590422}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
--- !u!1 &1726972099
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 1726972101}
- 108: {fileID: 1726972100}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &1726972100
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1726972099}
m_Enabled: 1
serializedVersion: 6
m_Type: 1
m_Color: {r: 1, g: .956862748, b: .839215696, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_Strength: 1
m_Bias: .0500000007
m_NormalBias: .400000006
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_BounceIntensity: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
m_AreaSize: {x: 1, y: 1}
--- !u!4 &1726972101
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1726972099}
m_LocalRotation: {x: .408217937, y: -.234569728, z: .109381676, w: .875426054}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalPosition.x
value: 1.30999994
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalPosition.y
value: 1.27999997
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalPosition.z
value: -8.47000027
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 464732, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 3135019c33394eb4f917b222e3ecbddb, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1768239005
GameObject:
m_ObjectHideFlags: 0
@ -249,7 +158,7 @@ Transform:
m_Children:
- {fileID: 1945388283}
m_Father: {fileID: 0}
m_RootOrder: 0
m_RootOrder: 1
--- !u!82 &1768239007
AudioSource:
m_ObjectHideFlags: 0
@ -360,16 +269,23 @@ MonoBehaviour:
m_GameObject: {fileID: 1768239005}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 05ec5cf00ca181d45a42ba1870e148c3, type: 3}
m_Script: {fileID: 11500000, guid: 4bcce75dab8f540b797340354c772d8b, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IsWalking: 0
m_WalkSpeed: 5
m_RunSpeed: 10
m_RunstepLenghten: .699999988
m_JumpSpeed: 10
m_StickToGroundForce: 10
m_GravityMultiplier: 2
m_NbrAllumettes: 10
m_Briquets:
- {fileID: 11418934, guid: 303650e9a23c68a42876df290e9d7537, type: 2}
- {fileID: 11418934, guid: 303650e9a23c68a42876df290e9d7537, type: 2}
- {fileID: 11418934, guid: 303650e9a23c68a42876df290e9d7537, type: 2}
m_Allumettes: {fileID: 11455286, guid: bdd994d2c872c9e4d8601100f973be0d, type: 2}
m_WalkSpeed: 0
m_RunSpeed: 0
m_Stamina: 1000
m_RunstepLenghten: 0
m_JumpSpeed: 0
m_StickToGroundForce: 0
m_GravityMultiplier: 0
m_MouseLook:
XSensitivity: 2
YSensitivity: 2
@ -378,7 +294,7 @@ MonoBehaviour:
MaximumX: 90
smooth: 0
smoothTime: 5
m_UseFovKick: 1
m_UseFovKick: 0
m_FovKick:
Camera: {fileID: 0}
originalFov: 0
@ -387,23 +303,13 @@ MonoBehaviour:
TimeToDecrease: 1
IncreaseCurve:
serializedVersion: 2
m_Curve:
- time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
- time: 1
value: 1
inSlope: 2
outSlope: 2
tangentMode: 0
m_Curve: []
m_PreInfinity: 2
m_PostInfinity: 2
m_UseHeadBob: 1
m_UseHeadBob: 0
m_HeadBob:
HorizontalBobRange: .100000001
VerticalBobRange: .100000001
HorizontalBobRange: .330000013
VerticalBobRange: .330000013
Bobcurve:
serializedVersion: 2
m_Curve:
@ -434,16 +340,14 @@ MonoBehaviour:
tangentMode: 0
m_PreInfinity: 2
m_PostInfinity: 2
VerticaltoHorizontalRatio: 2
VerticaltoHorizontalRatio: 1
m_JumpBob:
BobDuration: .200000003
BobAmount: .100000001
m_StepInterval: 5
m_FootstepSounds:
- {fileID: 8300000, guid: 42e65e088b3f4374e851b8dbd38f3df9, type: 3}
- {fileID: 8300000, guid: 8bc94ec6ed537e743b481638bdcd503d, type: 3}
m_JumpSound: {fileID: 8300000, guid: 5897aeed9b676024fbb8c694b421a861, type: 3}
m_LandSound: {fileID: 8300000, guid: 3b09d59f4499d45428baa7a21e954296, type: 3}
BobDuration: 0
BobAmount: 0
m_StepInterval: 0
m_FootstepSounds: []
m_JumpSound: {fileID: 0}
m_LandSound: {fileID: 0}
--- !u!1 &1945388278
GameObject:
m_ObjectHideFlags: 0

22
Assets/Scripts/Briquet.cs Normal file
View File

@ -0,0 +1,22 @@
using UnityEngine;
using System.Collections;
public class Briquet : MonoBehaviour {
public float m_Essence=500;
public bool activer;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
if (activer)
{
m_Essence--;
print("SA brule");
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8ea23fececeb311438b15c556d9620f8
timeCreated: 1446994977
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,252 +6,370 @@ using Random = UnityEngine.Random;
namespace UnityStandardAssets.Characters.FirstPerson
{
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
public class FirstPersonController : MonoBehaviour
{
[SerializeField] private bool m_IsWalking;
[SerializeField] private float m_WalkSpeed;
[SerializeField] private float m_RunSpeed;
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
[SerializeField] private float m_JumpSpeed;
[SerializeField] private float m_StickToGroundForce;
[SerializeField] private float m_GravityMultiplier;
[SerializeField] private MouseLook m_MouseLook;
[SerializeField] private bool m_UseFovKick;
[SerializeField] private FOVKick m_FovKick = new FOVKick();
[SerializeField] private bool m_UseHeadBob;
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField] private float m_StepInterval;
[SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
[SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
[SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.
private Camera m_Camera;
private bool m_Jump;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
// Use this for initialization
private void Start()
{
m_CharacterController = GetComponent<CharacterController>();
m_Camera = Camera.main;
m_OriginalCameraPosition = m_Camera.transform.localPosition;
m_FovKick.Setup(m_Camera);
m_HeadBob.Setup(m_Camera, m_StepInterval);
m_StepCycle = 0f;
m_NextStep = m_StepCycle/2f;
m_Jumping = false;
m_AudioSource = GetComponent<AudioSource>();
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
public class FirstPersonController : MonoBehaviour
{
[SerializeField] private bool m_IsWalking;
[SerializeField] private int m_NbrAllumettes = 10;
[SerializeField] private Briquet[] m_Briquets;
[SerializeField] private Allumettes m_Allumettes;
[SerializeField] private float m_WalkSpeed;
[SerializeField] private float m_RunSpeed;
[SerializeField] private float m_Stamina =1000;
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
[SerializeField] private float m_JumpSpeed;
[SerializeField] private float m_StickToGroundForce;
[SerializeField] private float m_GravityMultiplier;
[SerializeField] private MouseLook m_MouseLook;
[SerializeField] private bool m_UseFovKick;
[SerializeField] private FOVKick m_FovKick = new FOVKick();
[SerializeField] private bool m_UseHeadBob;
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField] private float m_StepInterval;
[SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
[SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
[SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.
private Camera m_Camera;
private bool m_Jump;
private int indexBriquet;
private bool canSprint;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
private MilesStonesPARA currentMilestone;
// Use this for initialization
private void Start()
{
currentMilestone = GameObject.FindGameObjectWithTag ("MilesStones").GetComponent<MilesStonesPARA>();
m_CharacterController = GetComponent<CharacterController>();
m_Camera = Camera.main;
m_OriginalCameraPosition = m_Camera.transform.localPosition;
m_FovKick.Setup(m_Camera);
m_HeadBob.Setup(m_Camera, m_StepInterval);
m_StepCycle = 0f;
m_NextStep = m_StepCycle/2f;
m_Jumping = false;
m_AudioSource = GetComponent<AudioSource>();
m_MouseLook.Init(transform , m_Camera.transform);
}
}
// Update is called once per frame
private void Update()
{
RotateView();
// the jump state needs to read here to make sure it is not missed
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_MoveDir.y = 0f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
private void PlayLandingSound()
{
m_AudioSource.clip = m_LandSound;
m_AudioSource.Play();
m_NextStep = m_StepCycle + .5f;
}
private void FixedUpdate()
{
float speed;
GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height/2f);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
//Actions joueur
if(Input.GetButton("Briquet"))
{
//allumerBriquet
if(m_Briquets[indexBriquet]!=null)
{
//Si un briquet n'est pas déja allumé
if(!m_Briquets[indexBriquet].activer)
{
//Si il n'y a pas de briquet déja commencé
if(GameObject.FindGameObjectWithTag("Briquet")==null)
{
Instantiate(m_Briquets[indexBriquet]);
m_Briquets[indexBriquet] = GameObject.FindGameObjectWithTag("Briquet").GetComponent<Briquet>();
//Si il y a une allumette. Éteint la
}
if(GameObject.FindGameObjectWithTag("Allumettes")!=null)
{
m_NbrAllumettes--;
DestroyObject(GameObject.FindGameObjectWithTag("Allumettes"));
}
m_Briquets[indexBriquet].activer=true;
m_Briquets[indexBriquet].enabled = true;
}
//Si le briquet est déja allumé
else
{
m_Briquets[indexBriquet].activer=false;
m_Briquets[indexBriquet].enabled = false;
}
}
}
//Si le briquet est vide, le jeté
if (m_Briquets[indexBriquet].m_Essence <= 0)
{
m_Briquets[indexBriquet].activer=false;
DestroyObject(m_Briquets[indexBriquet].gameObject);
indexBriquet++;
}
if(Input.GetButton("Alumettes"))
{
//allumerAllumettes
if(m_NbrAllumettes>0)
{
//Si il y a un briquet, l'éteindre, mais le conservé
if(GameObject.FindGameObjectWithTag("Briquet")!=null)
{
m_Briquets[indexBriquet].activer=false;
m_Briquets[indexBriquet].enabled = false;
}
//Si il ny a pas d'allumettes déja allumé
if(GameObject.FindGameObjectWithTag("Allumettes")==null)
{
Instantiate(m_Allumettes);
GameObject.FindGameObjectWithTag("Allumettes").GetComponent<Allumettes>().activer=true;
}
}
}
//Si l'allumette est morte
if(GameObject.FindGameObjectWithTag("Allumettes")!=null)
if(GameObject.FindGameObjectWithTag("Allumettes").GetComponent<Allumettes>().m_Duree<=0)
{
m_NbrAllumettes--;
DestroyObject(GameObject.FindGameObjectWithTag("Allumettes"));
}
// Update is called once per frame
private void Update()
{
RotateView();
// the jump state needs to read here to make sure it is not missed
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
if(Input.GetButton("StopRespire"))
//Stopper la respiration et auguementer les sons
print("yo2");
else
//Repiration sounds
print("yo3");
if (m_CharacterController.isGrounded)
{
m_MoveDir.y = -m_StickToGroundForce;
if (m_Jump)
{
m_MoveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}
else
{
m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
ProgressStepCycle(speed);
UpdateCameraPosition(speed);
}
private void PlayJumpSound()
{
m_AudioSource.clip = m_JumpSound;
m_AudioSource.Play();
}
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (!(m_StepCycle > m_NextStep))
{
return;
}
m_NextStep = m_StepCycle + m_StepInterval;
PlayFootStepAudio();
}
private void PlayFootStepAudio()
{
if (!m_CharacterController.isGrounded)
{
return;
}
// pick & play a random footstep sound from the array,
// excluding sound at index 0
int n = Random.Range(1, m_FootstepSounds.Length);
m_AudioSource.clip = m_FootstepSounds[n];
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// move picked sound to index 0 so it's not picked next time
m_FootstepSounds[n] = m_FootstepSounds[0];
m_FootstepSounds[0] = m_AudioSource.clip;
}
private void UpdateCameraPosition(float speed)
{
Vector3 newCameraPosition;
if (!m_UseHeadBob)
{
return;
}
if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
{
m_Camera.transform.localPosition =
m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
(speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
}
else
{
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
}
m_Camera.transform.localPosition = newCameraPosition;
}
private void GetInput(out float speed)
{
// Read input
float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
float vertical = CrossPlatformInputManager.GetAxis("Vertical");
bool waswalking = m_IsWalking;
#if !MOBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !CrossPlatformInputManager.GetButton("Course");
//Si le joueur marche. Il reprend de l'énergie
if(m_IsWalking)
{
m_Stamina += 5;
if(m_Stamina >= 500)
canSprint=true;
if(m_Stamina >= 1000)
m_Stamina = 1000;
}
//Sinon il court, mais il perd de l'énergie
else
{
m_Stamina -= 10;
if(m_Stamina < 0)
{
canSprint=false;
m_Stamina=0;
}
}
//Si il n'a pas d'energie il doit marcher
if(!canSprint)
m_IsWalking=true;
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
m_Input = new Vector2(horizontal, vertical);
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1)
{
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
private void RotateView()
{
m_MouseLook.LookRotation (transform, m_Camera.transform);
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
Rigidbody body = hit.collider.attachedRigidbody;
//Si le joueur touche un piege le blessant
if(hit.collider.tag == "Trap")
{
hurtPlayer();
}
//dont move the rigidbody if the character is on top of it
if (m_CollisionFlags == CollisionFlags.Below)
{
return;
}
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_MoveDir.y = 0f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
private void PlayLandingSound()
{
m_AudioSource.clip = m_LandSound;
m_AudioSource.Play();
m_NextStep = m_StepCycle + .5f;
}
private void FixedUpdate()
{
float speed;
GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height/2f);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
if (m_CharacterController.isGrounded)
{
m_MoveDir.y = -m_StickToGroundForce;
if (m_Jump)
{
m_MoveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}
else
{
m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
ProgressStepCycle(speed);
UpdateCameraPosition(speed);
}
private void PlayJumpSound()
{
m_AudioSource.clip = m_JumpSound;
m_AudioSource.Play();
}
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (!(m_StepCycle > m_NextStep))
{
return;
}
m_NextStep = m_StepCycle + m_StepInterval;
PlayFootStepAudio();
}
private void PlayFootStepAudio()
{
if (!m_CharacterController.isGrounded)
{
return;
}
// pick & play a random footstep sound from the array,
// excluding sound at index 0
int n = Random.Range(1, m_FootstepSounds.Length);
m_AudioSource.clip = m_FootstepSounds[n];
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// move picked sound to index 0 so it's not picked next time
m_FootstepSounds[n] = m_FootstepSounds[0];
m_FootstepSounds[0] = m_AudioSource.clip;
}
private void UpdateCameraPosition(float speed)
{
Vector3 newCameraPosition;
if (!m_UseHeadBob)
{
return;
}
if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
{
m_Camera.transform.localPosition =
m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
(speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
}
else
{
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
}
m_Camera.transform.localPosition = newCameraPosition;
}
private void GetInput(out float speed)
{
// Read input
float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
float vertical = CrossPlatformInputManager.GetAxis("Vertical");
bool waswalking = m_IsWalking;
#if !MOBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
m_Input = new Vector2(horizontal, vertical);
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1)
{
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
private void RotateView()
{
m_MouseLook.LookRotation (transform, m_Camera.transform);
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
Rigidbody body = hit.collider.attachedRigidbody;
//dont move the rigidbody if the character is on top of it
if (m_CollisionFlags == CollisionFlags.Below)
{
return;
}
if (body == null || body.isKinematic)
{
return;
}
body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
}
}
if (body == null || body.isKinematic)
{
return;
}
body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
}
//Si le joueur est blessé, il est de retour au point de réapparition
public void hurtPlayer()
{
print ("I'm hurt");
m_Briquets [m_Briquets.Length - 1] = new Briquet ();
transform.position = currentMilestone.Respawn.transform.position;
transform.rotation = currentMilestone.Respawn.transform.rotation;
}
public void deathPlayer()
{
print ("I'm dead");
}
}
}

View File

@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
public class MilesStonesPARA : MonoBehaviour {
[SerializeField] private float timeMinToFinish;
[SerializeField] public GameObject Respawn;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9dc35e923ff865d4889ba28eb1b64fd5
timeCreated: 1446994977
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -186,8 +186,8 @@ InputManager:
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 0
altNegativeButton:
positiveButton: joystick button 8
altNegativeButton: left shift
altPositiveButton:
gravity: 1000
dead: .00100000005
@ -203,7 +203,7 @@ InputManager:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 1
altNegativeButton:
altNegativeButton: z
altPositiveButton:
gravity: 1000
dead: .00100000005
@ -219,7 +219,7 @@ InputManager:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 2
altNegativeButton:
altNegativeButton: x
altPositiveButton:
gravity: 1000
dead: .00100000005
@ -230,12 +230,12 @@ InputManager:
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
m_Name: StopRespire
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 3
altNegativeButton:
positiveButton: joystick button 9
altNegativeButton: space
altPositiveButton:
gravity: 1000
dead: .00100000005

View File

@ -8,6 +8,7 @@ PlayerSettings:
defaultScreenOrientation: 4
targetDevice: 2
targetResolution: 0
useOnDemandResources: 0
accelerometerFrequency: 60
companyName: DefaultCompany
productName: EscapeTheRoom
@ -28,6 +29,7 @@ PlayerSettings:
androidShowActivityIndicatorOnLoading: -1
iosAppInBackgroundBehavior: 0
displayResolutionDialog: 1
iosAllowHTTPDownload: 1
allowedAutorotateToPortrait: 1
allowedAutorotateToPortraitUpsideDown: 1
allowedAutorotateToLandscapeRight: 1
@ -135,6 +137,15 @@ PlayerSettings:
iOSLaunchScreenFillPct: 100
iOSLaunchScreenSize: 100
iOSLaunchScreenCustomXibPath:
iOSLaunchScreeniPadType: 0
iOSLaunchScreeniPadImage: {fileID: 0}
iOSLaunchScreeniPadBackgroundColor:
serializedVersion: 2
rgba: 0
iOSLaunchScreeniPadFillPct: 100
iOSLaunchScreeniPadSize: 100
iOSLaunchScreeniPadCustomXibPath:
iOSDeviceRequirements: []
AndroidTargetDevice: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
@ -152,8 +163,10 @@ PlayerSettings:
m_BuildTargetIcons:
- m_BuildTarget:
m_Icons:
- m_Icon: {fileID: 0}
m_Size: 0
- serializedVersion: 2
m_Icon: {fileID: 0}
m_Width: 0
m_Height: 0
m_BuildTargetBatching: []
m_BuildTargetGraphicsAPIs: []
webPlayerTemplate: APPLICATION:Default
@ -228,6 +241,8 @@ PlayerSettings:
ps4SdkOverride:
ps4BGMPath:
ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir:
@ -245,10 +260,13 @@ PlayerSettings:
ps4pnGameCustomData: 1
playerPrefsSupport: 0
ps4ReprojectionSupport: 0
ps4UseAudio3dBackend: 0
ps4Audio3dVirtualSpeakerCount: 14
ps4attribUserManagement: 0
ps4attribMoveSupport: 0
ps4attrib3DSupport: 0
ps4attribShareSupport: 0
ps4IncludedModules: []
monoEnv:
psp2Splashimage: {fileID: 0}
psp2NPTrophyPackPath: