//------------------------------------------------------------------------------- /// //------------------------------------------------------------------------------- public CPlayer(Vector2 posInit, bool bIsMainCharacter = false) { game = GameObject.Find("_Game").GetComponent <CGame>(); GameObject prefab = game.prefabPlayer; m_GameObject = GameObject.Instantiate(prefab) as GameObject; SetPosition2D(posInit); m_ConeVision = m_GameObject.GetComponent <CConeVision>(); m_CameraCone = game.m_CameraCone; m_fSpeed = game.m_fSpeedPlayer; m_spriteSheet = new CSpriteSheet(m_GameObject); // m_GameObject.GetComponent<CSpriteSheet>(); m_AnimRepos = new CAnimation(game.m_materialPlayerRepos, 1, 1, 1.0f); m_AnimHorizontal = new CAnimation(game.m_materialPlayerHorizontal, 6, 1, 6.0f, new string[] { "", "", "Play_Foost", "", "", "Play_Foost" }); m_AnimVertical = new CAnimation(game.m_materialPlayerVertical, 6, 1, 2.0f); m_eMoveModState = EMoveModState.e_MoveModState_marche; m_bMainCharacter = bIsMainCharacter; m_YounesSuceDesBites = null; m_bHaveObject = false; m_Torche = m_GameObject.transform.FindChild("Torche").gameObject; m_CercleDiscretion = m_GameObject.transform.FindChild("CercleDiscretion").GetComponent <CCercleDiscretion>(); }
//------------------------------------------------------------------------------- /// //------------------------------------------------------------------------------- void MovePlayer(float fDeltatime) { if (m_GameObject.rigidbody != null) { Vector3 velocity = Vector3.zero; if (CApoilInput.MoveUp) { velocity += new Vector3(0, 1, 0); m_spriteSheet.SetAnimation(m_AnimVertical); m_spriteSheet.AnimationStart(); m_eMoveModState = EMoveModState.e_MoveModState_marche; } if (CApoilInput.MoveDown) { velocity += new Vector3(0, -1, 0); m_spriteSheet.SetAnimation(m_AnimVertical); m_spriteSheet.AnimationStart(); m_eMoveModState = EMoveModState.e_MoveModState_marche; } if (CApoilInput.MoveLeft) { velocity += new Vector3(-1, 0, 0); m_spriteSheet.SetAnimation(m_AnimHorizontal); m_spriteSheet.AnimationStart(); flipLeft(); m_eMoveModState = EMoveModState.e_MoveModState_marche; } if (CApoilInput.MoveRight) { velocity += new Vector3(1, 0, 0); m_spriteSheet.SetAnimation(m_AnimHorizontal); m_spriteSheet.AnimationStart(); flipRight(); m_eMoveModState = EMoveModState.e_MoveModState_marche; } if (!CApoilInput.MoveUp && !CApoilInput.MoveDown && !CApoilInput.MoveLeft && !CApoilInput.MoveRight) { m_spriteSheet.SetAnimation(m_AnimRepos); m_spriteSheet.AnimationStop(); m_eMoveModState = EMoveModState.e_MoveModState_attente; m_GameObject.rigidbody.velocity = Vector3.zero; } velocity.Normalize(); m_DirectionDeplacement = velocity; if (CApoilInput.WalkFast) { m_eMoveModState = EMoveModState.e_MoveModState_cours; } if (CApoilInput.WalkSlow) { m_eMoveModState = EMoveModState.e_MoveModState_discret; } CalculateSpeed(); m_GameObject.transform.position += m_fSpeed * velocity * fDeltatime; } else { Debug.LogError("Pas de rigid body sur " + m_GameObject.name); } }