Text not changing from action in viewdidappear

In arkit I have 3d text in which via button I am trying to change the colors to. The code below is not working. It stays red the entire no matter how many times the button is being pressed. But the counter score is increased.

                   class TextNode: SCNNode{
  var textGeometry: SCNText!
    init(text: String, depth: CGFloat = 1, font: String = "Helvatica", textSize: CGFloat = 3, colour: UIColor) {
super.init()
textGeometry = SCNText(string: text , extrusionDepth: depth)
textGeometry.font = UIFont(name: font, size: textSize)
textGeometry.flatness = 0
textGeometry.firstMaterial?.diffuse.contents = colour
self.geometry = textGeometry
self.scale = SCNVector3(0.01, 0.01 , 0.01)
  }
 required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
   }
  }
 var counter = 0
var textNode: TextNode!
override func viewDidAppear(_ animated: Bool) {
   augmentedRealityView.session.run(configuration)


    textNode = TextNode(text: textChangerField.text!, colour: .blue)
   

    augmentedRealityView.scene.rootNode.addChildNode(textNode)
    textNode.position = SCNVector3(0, 0, -1.5)
augmentedRealityView.automaticallyUpdatesLighting = true
textChangerField.delegate = self
  }

   @IBAction func changeTextColour(){

 counter += 1

changeColour(counter)
 }

 func changeColour(_ value: Int){

    if value == 0{
      textNode.textGeometry.firstMaterial?.diffuse.contents = UIColor.red
   }else if value == 1{
 textNode =  textNode.textGeometry.firstMaterial?.diffuse.contents = UIColor.cyan
  }else if value == 2{
  textNode.textGeometry.firstMaterial?.diffuse.contents = UIColor.yellow
    }}

Swift has no idea that arkit has been invented yet.

This topic was automatically closed after 166 days. New replies are no longer allowed.