private void Start() { //sets the initial home position Home = transform.position; _flippable = GetComponent <Flippable>(); }
private void Awake() { _rigid = GetComponent <Rigidbody2D>(); _collider = GetComponent <Collider2D>(); _flippable = GetComponent <Flippable>(); _multiSoundPlayer = GetComponent <MultiSoundPlayer>(); }
void getState() { AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(0); if (currentState.IsName("idle") || currentState.IsName("walk")) { interruptable = Interruptable.Yes; flippable = Flippable.Yes; moveable = Moveable.Yes; } else if (currentState.IsName("crouch")) { interruptable = Interruptable.Yes; flippable = Flippable.No; moveable = Moveable.No; } else if (currentState.IsName("air") || currentState.IsName("jumptoair") || currentState.IsName("air_P2")) { interruptable = Interruptable.Yes; flippable = Flippable.No; moveable = Moveable.Yes; } else { interruptable = Interruptable.No; flippable = Flippable.No; } if (currentState.IsName("Land")) { moveable = Moveable.No; } }
void Start() { var player = FindObjectOfType <PlayerController>(); playerOrientation = player.gameObject.GetComponent <Flippable>(); SpawnBirds(); }
private void Awake() { _rigid = GetComponent <Rigidbody2D>(); _spriteAnimator = GetComponent <SpriteAnimator>(); _flippable = GetComponent <Flippable>(); _wallJump = GetComponent <WallJump>(); _spriteRenderer = GetComponent <SpriteRenderer>(); }
public void selectMainFlippableShape() { flippable = transform.GetChild(0).gameObject; flippableScript = transform.GetChild(0).GetComponent <Flippable>(); flippableScript.initializeFlippableShape(); colorFlippableScript = flippable.GetComponent <ColorFlippable>(); }
private void Awake() { _rigid = GetComponent <Rigidbody2D>(); _flippable = GetComponent <Flippable>(); _multiSoundPlayer = GetComponent <MultiSoundPlayer>(); //Sets up the default ground mask for OnGround2D() CommonExtensions.DefaultGroundMask = Commons.Masks.GroundOnly; }
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("PlayerGhost")) { GameObject ghostFlippableGO = other.transform.parent.gameObject; Flippable ghostFlippableScript = ghostFlippableGO.GetComponent <Flippable>(); ghostFlippableScript.barrierHitGhost(); } }
public void createAndFlipGhostKeyboard(Vector3 direction) { // Create ghost of player in same location, with this as parent GameObject ghost = Instantiate(flippable, transform); // Initialize Flippable ghostFlippableScript = ghost.GetComponent <Flippable>(); ghostFlippableScript.initializeFlippableShape(); // Make FlippableShape into Ghost ghostFlippableScript.makeIntoGhost(); // Disable ghost mesh ghostFlippableScript.disableMeshRenderer(); // Flip ghost towards click to check for collisions. Should be destroyed if it hits barrier object. ghostFlippableScript.flip180DegGhostKeyboard(direction); }
void OnEnable() { flip = GetComponentInParent <Flippable>(); position = Physics.FromUnity(transform.position); if (GetComponent <Flippable>() != null) { mask |= CollisionMask.Flipping; } if (flip != null) { flip.EndFlip += (delta) => { position = Physics.FromUnity(transform.position); }; } Physics.Enable(this); }
protected override void Start() { base.Start(); _rigidbody = GetComponent <Rigidbody2D>(); _shooter = GetComponentInChildren <WeaponFireHurtbox>().Shooter.gameObject; _shooterFlippable = _shooter.GetComponent <Flippable>(); //Makes the bullet affected by gravity _rigidbody.gravityScale = 1; //Decide the direction of the projectile int direction = Math.Sign(transform.up.x); if (direction == 0) { direction = _shooterFlippable.DirectionSign; } //Set horizontal speed _rigidbody.SetVelocityX(Speed * direction); _horizontalSpeed = _rigidbody.velocity.x; }
private void Start() { _parent = gameObject.GetComponentInParent <Flippable>(); }
protected virtual void Awake() { _flippable = GetComponent <Flippable>(); _collider = GetComponent <Collider2D>(); }
private void Awake() { _flippable = GetComponent <Flippable>(); }
/// <summary> /// Extracts a new position snapshot from the provided object /// </summary> /// <param name="obj"></param> /// <returns></returns> public static PositionSnapshot FromObject(Flippable obj) { return(new PositionSnapshot(obj.transform.position, obj.Direction, DateTime.Now)); }
protected void Awake() { _flippable = GetComponent <Flippable>(); }
public void Interact() { if (Input.GetKeyDown(KeyCode.I) == true) { if (UIManager.hasInventoryOpen() == false) { UIManager.ShowInventory(GameMaster.Instance.player.getInventory()); } else { UIManager.CloseInventory(); } } if (Input.GetKeyDown(KeyCode.F) == true) { currentPaletteIndex = Util.WrapInt(currentPaletteIndex += 1, 2, Enum.GetValues(typeof(Voxel)).Length - 1); currentVoxel = (Voxel)currentPaletteIndex; UIManager.ForceUpdate(); } // Everything below here can't be done when mousing over non-clickthrough UI if (UIManager.isMouseOverUIWithIgnore() == true) { return; } Unity.Physics.RaycastHit hit; Unity.Entities.Entity hitEntity; hitData = null; if (GameMaster.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), 8, out hit, out hitEntity)) { hitData = new VoxelHitData(hit, hitEntity); Vector3 offsetPos = hitData.hitTransform.InverseTransformPoint(hit.Position); offsetPos.x = (float)Math.Round(offsetPos.x); offsetPos.y = (float)Math.Round(offsetPos.y); offsetPos.z = (float)Math.Round(offsetPos.z); // offsetPos.x = offsetPos.x - offsetPos.x % 1; // offsetPos.y = offsetPos.y - offsetPos.y % 1; // offsetPos.z = offsetPos.z - offsetPos.z % 1; offsetPos = hitData.hitTransform.rotation * offsetPos; Vector3 hitPos = hitData.hitTransform.position + offsetPos; Debug.DrawLine(Camera.main.ScreenPointToRay(Input.mousePosition).origin, hitPos, Color.red); Debug.DrawRay(hit.Position, hit.SurfaceNormal, Color.yellow); Debug.DrawRay(hit.Position, hit.SurfaceNormal * -0.5f, Color.cyan); } else { Debug.DrawRay(Camera.main.ScreenPointToRay(Input.mousePosition).origin, Camera.main.ScreenPointToRay(Input.mousePosition).direction * 8, Color.green); } // if (hit.collider != null) // { // Interactable interactable = hit.collider.GetComponent<Interactable>(); // if (interactable != null) // { // if (Input.GetMouseButtonDown(1) == true) // { // interactable.TryInteract(GameMaster.Instance.player.gameObject); // return; // } // else // { // interactable.TryHover(GameMaster.Instance.player.gameObject); // } // } // } Item mainHand = GameMaster.Instance.player.getEquipment().getSlot(EquipmentSlot.MAINHAND); if (mainHand.isValid() == false) { return; } if (Input.GetKeyDown(KeyCode.G) == true) { int amountToDrop = 1; if (Input.GetKey(KeyCode.LeftControl) == true || Input.GetKey(KeyCode.RightControl) == true) { amountToDrop = mainHand.getAmount(); } GameMaster.Instance.DropItemNaturally(Position.fromVector3(transform.position + (transform.forward * 3)), mainHand, amountToDrop); GameMaster.Instance.player.getInventory().Remove(mainHand, amountToDrop); } if (hitData == null || hitData.isValid() == false) { return; } if (mainHand is BLOCKITEM) { rotationOrientation = hitData.getFace().getOpposite(); currentVoxel = ((BLOCKITEM)mainHand).getVoxel(); if (Input.GetAxis("Mouse ScrollWheel") > 0) { rotationIndex = Util.WrapInt(rotationIndex += 1, 0, 3); rotationDirection = (Direction)rotationIndex; } else if (Input.GetAxis("Mouse ScrollWheel") < 0) { rotationIndex = Util.WrapInt(rotationIndex -= 1, 0, 3); rotationDirection = (Direction)rotationIndex; } if (Input.GetMouseButtonDown(1) == true) { if (hitData.getAtFace().getType() == Voxel.VOID) { Block thisBlock = hitData.voxelObject.setBlockAt(hitData.atFace, currentVoxel); if (thisBlock.getChunk() != null) { GameMaster.Instance.player.getInventory().Remove(mainHand, 1); GameMaster.Instance.PlaySound(placeSound, hit.Position); GetComponent <MotionAnimator>().PlayMotion("mainHandAttack"); if (thisBlock.getBlockData() is Rotatable) { Rotatable data = (Rotatable)thisBlock.getBlockData(); data.setDirection(rotationDirection); thisBlock.setBlockData(data); } if (thisBlock.getBlockData() is Orientated) { Orientated data = (Orientated)thisBlock.getBlockData(); data.setOrientation(rotationOrientation); thisBlock.setBlockData(data); } if (hitData.getFace() == Direction.BELOW) { if (thisBlock.getBlockData() is Flippable) { Flippable data = (Flippable)thisBlock.getBlockData(); data.setFlipped(true); thisBlock.setBlockData(data); } } } } } UpdateDisplayModel(); DrawDisplayModel(hitData.localFacePosition); } else if (mainHand is CUTTER) { Block clickedBlock = hitData.getAt(); if (Input.GetMouseButtonDown(0) == true) { if (clickedBlock.getType() != Voxel.VOID && clickedBlock.getType() != Voxel.SHIP_CORE) { Position droppedPosition = Position.fromVector3(hit.Position); GameMaster.Instance.DropItemNaturally(droppedPosition, clickedBlock.getType(), 1); Block thisBlock = hitData.voxelObject.setBlockAt(hitData.atHit, Voxel.VOID); if (thisBlock.getChunk() != null) { GameMaster.Instance.PlaySound(placeSound, hit.Position); GetComponent <MotionAnimator>().PlayMotion("mainHandAttack"); } } } else if (Input.GetMouseButtonDown(1) == true) { if (clickedBlock.getType() != Voxel.VOID && clickedBlock.getType() != Voxel.SHIP_CORE) { Block thisBlock = hitData.voxelObject.setBlockAt(hitData.atHit, Voxel.FRAME); if (thisBlock.getChunk() != null) { GameMaster.Instance.PlaySound(placeSound, hit.Position); GetComponent <MotionAnimator>().PlayMotion("mainHandAttack"); } } } currentVoxel = clickedBlock.getType(); if (clickedBlock.getBlockData() is Rotatable) { Rotatable data = (Rotatable)clickedBlock.getBlockData(); rotationDirection = data.getDirection(); } if (clickedBlock.getBlockData() is Orientated) { Orientated data = (Orientated)clickedBlock.getBlockData(); rotationOrientation = data.getOrientation(); } UpdateDisplayModel(); DrawDisplayModel(hitData.localPosition); } else if (mainHand is DRILL) { if (hitData.isValid()) { rotationOrientation = hitData.getFace().getOpposite(); if (Input.GetAxis("Mouse ScrollWheel") > 0) { rotationIndex = Util.WrapInt(rotationIndex += 1, 0, 3); rotationDirection = (Direction)rotationIndex; } else if (Input.GetAxis("Mouse ScrollWheel") < 0) { rotationIndex = Util.WrapInt(rotationIndex -= 1, 0, 3); rotationDirection = (Direction)rotationIndex; } if (Input.GetMouseButtonDown(2) == true) { Block clickedBlock = hitData.getAt(); if (clickedBlock.getType() != Voxel.VOID && clickedBlock.getType() != Voxel.SHIP_CORE) { currentVoxel = clickedBlock.getType(); currentPaletteIndex = (int)currentVoxel; } } if (Input.GetMouseButtonDown(1) == true) { if (hitData.getAt().getType() == Voxel.FRAME) { Block thisBlock = hitData.voxelObject.setBlockAt(hitData.atHit, currentVoxel); if (thisBlock.getChunk() != null) { GameMaster.Instance.PlaySound(placeSound, hit.Position); GetComponent <MotionAnimator>().PlayMotion("mainHandAttack"); if (thisBlock.getBlockData() is Rotatable) { Rotatable data = (Rotatable)thisBlock.getBlockData(); data.setDirection(rotationDirection); thisBlock.setBlockData(data); } if (thisBlock.getBlockData() is Orientated) { Orientated data = (Orientated)thisBlock.getBlockData(); data.setOrientation(rotationOrientation); thisBlock.setBlockData(data); } if (hitData.getFace() == Direction.BELOW) { if (thisBlock.getBlockData() is Flippable) { Flippable data = (Flippable)thisBlock.getBlockData(); data.setFlipped(true); thisBlock.setBlockData(data); } } } } } UpdateDisplayModel(); DrawDisplayModel(hitData.localPosition); } } }
void Start() { parentFlippableScript = transform.parent.GetComponent <Flippable>(); }
public void UpdateDisplayModel() { List <Vector3> vertices = new List <Vector3>(); List <int> triangles = new List <int>(); List <Vector3> normals = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <Color> colors = new List <Color>(); Block thisBlock = currentVoxel.toBlock(); if (thisBlock.getBlockData() is Rotatable) { Rotatable data = (Rotatable)thisBlock.getBlockData(); data.setDirection(rotationDirection); thisBlock.setBlockData(data); } if (thisBlock.getBlockData() is Orientated && hitData != null) { Orientated data = (Orientated)thisBlock.getBlockData(); data.setOrientation(rotationOrientation); thisBlock.setBlockData(data); } if (hitData != null && hitData.getFace() == Direction.BELOW) { if (thisBlock.getBlockData() is Flippable) { Flippable data = (Flippable)thisBlock.getBlockData(); data.setFlipped(true); thisBlock.setBlockData(data); } } switch (thisBlock.getModelType()) { case ModelType.CUBE: ModelBuilder.Cube.Top(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.Bottom(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.North(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.East(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.South(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.West(vertices, triangles, normals, uvs, colors, thisBlock); break; case ModelType.SLOPE: ModelBuilder.Slope.Face(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Slope.Bottom(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Slope.North(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Slope.East(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Slope.West(vertices, triangles, normals, uvs, colors, thisBlock); break; case ModelType.CUSTOM: ModelBuilder.Custom.Build(vertices, triangles, normals, uvs, colors, thisBlock.getModelData(), thisBlock); break; case ModelType.CUSTOM_CUBE: ModelBuilder.Cube.Top(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.Bottom(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.North(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.South(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.East(vertices, triangles, normals, uvs, colors, thisBlock); ModelBuilder.Cube.West(vertices, triangles, normals, uvs, colors, thisBlock); break; case ModelType.CROSS_SECTION_SMALL: ModelBuilder.CrossSection.Small.Build(vertices, triangles, normals, uvs, colors, thisBlock); break; case ModelType.CUBE_HALF: Vector3 scale = new Vector3(1.0f, 1.0f, 0.5f); ModelBuilder.Cube.Top(vertices, triangles, normals, uvs, colors, thisBlock, scale); ModelBuilder.Cube.Bottom(vertices, triangles, normals, uvs, colors, thisBlock, scale); ModelBuilder.Cube.North(vertices, triangles, normals, uvs, colors, thisBlock, scale); ModelBuilder.Cube.South(vertices, triangles, normals, uvs, colors, thisBlock, scale); ModelBuilder.Cube.East(vertices, triangles, normals, uvs, colors, thisBlock, scale); ModelBuilder.Cube.West(vertices, triangles, normals, uvs, colors, thisBlock, scale); break; } for (int i = 0; i < vertices.Count; i++) { vertices[i] -= Vector3.one * 0.5f; } displayModel.Clear(); displayModel.vertices = vertices.ToArray(); displayModel.triangles = triangles.ToArray(); displayModel.normals = normals.ToArray(); displayModel.uv = uvs.ToArray(); displayModel.colors = colors.ToArray(); }