Advertisement
Caminhoneiro

Bitwise stuff

Feb 24th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class AttributeManager : MonoBehaviour
  8. {
  9.     public static int MAGIC = 16, INTELLIGENCE = 8, CHARISMA = 4, FLY = 2, INVISIBLE = 1;
  10.     public Text attributeDisplay;
  11.     public int attributes = 0;
  12.    
  13.     private void OnTriggerEnter(Collider other) {
  14.         if(other.gameObject.tag == "MAGIC")
  15.             attributes |= MAGIC;
  16.         if(other.gameObject.tag == "INTELLIGENCE")
  17.             attributes |= INTELLIGENCE;
  18.         if(other.gameObject.tag == "CHARISMA")
  19.             attributes |= CHARISMA;
  20.         if(other.gameObject.tag == "FLY")
  21.             attributes |= FLY;
  22.         if(other.gameObject.tag == "INVISIBLE")
  23.             attributes |= INVISIBLE;
  24.         else if(other.gameObject.tag == "ANTI-MAGIC")
  25.             attributes &= ~(MAGIC);
  26.  
  27.         if(other.gameObject.tag == "MAGE")
  28.             attributes |= (MAGIC | INTELLIGENCE | CHARISMA);
  29.  
  30.         if(other.gameObject.tag == "ANTI-MAGE")
  31.             attributes &= ~(INTELLIGENCE | MAGIC);
  32.     }
  33.  
  34.     void resetAttributes()
  35.     {
  36.         attributes = 0;
  37.     }
  38.  
  39.     void Update()
  40.     {
  41.         Vector3 screenPoint = Camera.main.WorldToScreenPoint(this.transform.position);
  42.         attributeDisplay.transform.position = screenPoint + new Vector3(0,-50,0);
  43.  
  44.         attributeDisplay.text = Convert.ToString(attributes, 2).PadLeft(8, '0');
  45.  
  46.  
  47.         if(Input.GetKeyDown(KeyCode.Space)){
  48.             resetAttributes();
  49.         }
  50.     }
  51.        
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement